int main(){
int a[3]={1,10,20};
int *p=a;
printf("%d %d " ,*++p,*p);
return 0;
}
The output to the code above is 10 1 on a gcc compiler.
I understand that *++p increments p and dereferences the new value. But since p has been incremented, why does *p return 1 instead of 10?
*++p
will do (first increment, then dereference), it is not clear whether this or the following*p
is evaluated first. As such, the output of your program is... kind of random (or more specifically, compiler-specific). It is therefore not possible to "understand" the code.