This is what I think the ++
operator does
a++; // a+=1 after calculating this line
++a; // a+=1 before calcuating this line
I'm trying to study pointers, and I think that I misunderstood something.
int a=10;
int arr[3]={0,1,2};
int *ptr;
ptr=arr;
printf("%d,%d,%d,%d\n",a++,a++,++a,++a);
printf("%d,%d,%d\n", ptr[0],ptr[1],ptr[2]);
printf("%d,%d,%d,%d,%d,%d", * ptr++, ( * ptr)++, ++ * ptr, ++( * ptr), *++ptr, * ptr);
I expected that the output to be:
12, 12, 12, 12
0,1,2
3,3,3,3,3,3,3
But it wasn't. It was this:
13,12,14,14
0,1,2
4,3,2,2,2,2
Why is this?