I was trying to print an array's elements using a pointer and could do it by incrementing the pointer variable within a for loop.
int array[10] = {9,8,7,6,5,4,3,2,1,0};
int count, *ptr;
ptr= array;
for(count = 0; count < 10; count++)
{
printf("\n %d", *ptr++);
}
I've learnt that after declaration if we use *
with the pointer variable it is de-reference. So to write this *ptr++
in another way (if in the first iteration) is like array[0]++
right?
What I want to know is that ,how come this increment array[0]++
prints the next element in the array instead of incrementing the value of current element. As an example, the 0th element is 9, so incrementing it by one would be 10. But it prints the next element. What exactly is happening here?