#include<stdio.h>
int main()
{
int *p;
int arr[]={10,20};
p=arr;
++*p; //expected evaluation = (++(*p))
printf("arr[0]=%d, arr[1]= %d, p=%d\n",arr[0],arr[1],*p);
}
Output = arr[0]=11, arr[1]= 20, p=11
which is totally fine. But, here
#include<stdio.h>
int main()
{
int *p;
int arr[]={10,20};
p=arr;
++*p++; //expected evaluation = (++(*(p++))) = *p->20 , thus ++20 = 21
printf("arr[0]=%d, arr[1]= %d, p=%d\n",arr[0],arr[1],*p);
}
Since the priority of postfix ++
is higher, the value of a[1]
or *p
should be 21 but is:
arr[0]=11, arr[1]= 20, p=20
For some reason it doesn't increment? Why?