I am learning C and would like to ask about best practices.
Here two implementations (shirt is struct):
implementation1 :
void printShirt(shirt shirt){
printf("(%d , %s)",shirt.size,shirt.color);
}
void printShirts(shirt * shirts, int nbShirts){
int i;
for(i=0;i<nbShirts;i++) printShirt(shirts[i]);
printf("\n");
}
implementation 2:
void printShirt(shirt * shirt){
printf("(%d , %s)",shirt->size,shirt->color);
}
void printShirts(shirt * shirts, int nbShirts){
int i;
for(i=0;i<nbShirts;i++) printShirt(&shirts[i]);
printf("\n");
}
If I am correct (?), in implementation 1 the data of each shirt is copied from heap to stack before print. But this does not happen in implementation 2 (?).
For big arrays and structure might this have an impact ? Is there some best practice to follow ?