Hello I was reading this question, I got confused with how if we can pass arrays by value or not. Here is a piece of code which I think should pass array by value.
#include <cstdio>
void foo (int arr[]);
int main()
{
int arr[10];
foo(arr[10]);
return 0;
}
void foo (int arr[])
{
.......
}
Please tell me why wouldn’t it pass by value?
Thanks
Arrays automatically decay into pointers in certain contexts in C. Function calls are one of those places. That said, you are passing the pointer by value – C has no other way to pass parameters than “by value”.