0
Can anyone help me with this question?
int *P, A[3] = {0, 1, 2}; P = A; *(P+2) = 5; P = A++; *P = 7; What are the values stored in the array A from index 0 to index 2 after execution of the above code?
3 ответов
+ 1
Got error message 'lvalue expected ...' on this line `P = A++;`, but it can work if we replace it by `P = A + 1;` by which we have 0, 7, 5 in array <A> (may not be what you meant to do).
I couldn't quite explain though, I'm just bookmarking this to get notified when an explanation is given 👍
0
Why don't you use printf() to see them?
0
I see, we cannot postincrement an array address A.
You could do
*(P++ + 2) = 5;
and remove the next line which gives the error, and obtain 0,7,5
but take into account that a postincrement would assign (if it worked) A to P, and not A+1
In that case you would obtain 7,1,5