I read in the K&R C book that when we pass an array to a function, the address of the array (a pointer containing the address of the first element of the array) is passed to the function, therefore making it seem like a pass-by-reference (although there is no such real mechanism in C)
However, the below doesn't make sense to me then -
void test(char arr[10]) {
arr[2] = 'a';
}
main() {
char arr[5] = "hello";
test(arr);
printf("%s", arr);
return 0;
}
This gives me healo as expected.
But does that mean that this is how this is evaluated?
The "char arr[]" argument getting assigned the pointer to the actual array? How does that work?
char arr[10] = &arr[0]
doesn't make sense to me!