Page 177 - C-Language
P. 177
friend_indexes[i] = 1;
}
}
Here the static inside the [] of the function parameter, request that the argument array must have
at least as many elements as are specified (i.e. size elements). To be able to use that feature we
have to ensure that the size parameter comes before the array parameter in the list.
Use getListOfFriends() like this:
#define LIST_SIZE (50)
int main(void) {
size_t size_of_list = LIST_SIZE;
int friends_indexes[size_of_list];
getListOfFriends(size_of_list, friend_indexes); /* friend_indexes decays to a pointer to the
address of its 1st element:
&friend_indexes[0] */
/* Here friend_indexes carries: {0, 1, 2, ..., 49}; */
return 0;
}
See also
Passing multidimensional arrays to a function
Parameters are passed by value
In C, all function parameters are passed by value, so modifying what is passed in callee functions
won't affect caller functions' local variables.
#include <stdio.h>
void modify(int v) {
printf("modify 1: %d\n", v); /* 0 is printed */
v = 42;
printf("modify 2: %d\n", v); /* 42 is printed */
}
int main(void) {
int v = 0;
printf("main 1: %d\n", v); /* 0 is printed */
modify(v);
printf("main 2: %d\n", v); /* 0 is printed, not 42 */
return 0;
}
You can use pointers to let callee functions modify caller functions' local variables. Note that this is
not pass by reference but the pointer values pointing at the local variables are passed.
https://riptutorial.com/ 153

