I have the following function:
void foo(int arr[])
{
arr++; // No error. If I dereference arr and print it, I get 2
}
int main()
{
int x[3];
x[0]=1;
x[1]=2;
x[2]=3;
foo(x); //No error
x++; //Error.
}
Why don't I get an error when I carry out the operation in foo() but I get one when I do it in main? As far as I know, both arr in foo() and x in main() are pointers to the exact same location, the first element in x. So I should've been able to perform both x++ and arr++.