I was revisiting pointers when I had this doubt.
int *ptr;
int arr[5] = {10,20,30,40,50};
ptr = &arr[0];
Now printf("Value: %d",*ptr);
would print 10
if I do:
ptr++;
printf("Value: %d",*ptr);
the result would be: 20
Similarly if I do:
*ptr++;
printf("Value: %d",*ptr);
the result is: 30
But
printf("Value: %d",++*ptr);
gives me 31
I thought since ptr
is of type int
when I increment it, it would jump 4 bytes to the next memory location. But why does it show the same behavior for *ptr++
and ptr++
and not for ++*ptr
?