Hello friends,
I have a code snippet related to pointer increment and decrement.
int arr[] = {1,2,3,4,5};
int *ptr;
ptr = arr + 2;
printf("%d %d %d %d %d %d\n",ptr,(ptr+1),ptr--,ptr,ptr++,++ptr);
It is giving console output as:
1245020 1245024 1245024 1245020 1245020 1245020
I am a bit surprised with the third output 1245024 for ptr--
My expectation was 1245016.
(Right to left priority for unary operators).
There is no change in fifth and sixth outputs also.Why?
Tried it in VS2008.