Say I have a structure of:
typedef struct{
int data[5];
}ArrayList;
With a main function of:
int main(int argc, char *argv[]) {
ArrayList test = {1,2,3,4,5};
int x;
change(test);
return 0;
}
change function body:
void change(ArrayList arr){
printf("%d",arr.data);
}
The way I understand this is that since it's a pass by copy, it passes down the value of test, and arr takes that value.
Since int data[5] is an array, it can't actually pass down all its actual members at once, in this case, the integers, so it gives the address of the first member (test.data[0]). It can only do so one by one like data[0], data[1], ... So I'm assuming that arr.data here should have the value as test.data (talking about the pointer to the first member, so the address).
But for some reason if I print the value of arr.data it's displaying a completely different address from test.data's value, and when I print the members of arr it has all the members of test.data.
I'm seeing it as something similar if I declared something like:
int data[5] = {1,2,3,4,5};
printf("%d", data);
change(data);
then
void change(int data[]){
printf("%d", data); // this would have the same value as the statement above.
}
How does arr.test get its value?