I am new to pointers and learning basics of pointers. I want to know the difference between *ptr and *(&ptr + 1) from the below code.
#include<stdio.h>
int main()
{
int a[3] = {1, 2, 3};
int *ptr = a;
printf("*ptr = %d\n",*ptr);
printf("&ptr = %p\n",&ptr);
printf("(&ptr + 1) = %p\n",(&ptr + 1));
printf("*(&ptr + 1) = %d\n",*(&ptr + 1));
return 0;
}
From my analysis gcc produced the following output,
*ptr = 1 // as ptr = a, Ultimately *ptr will print the first value of array i.e. 1
&ptr = 0x7fffa7e97788 // Starting Address of array or address of first element
(&ptr + 1) = 0x7fffa7e97790 //address of next element in the array
*(&ptr + 1) = 1 // I want to know how this is getting dereffered
Thanks in Advance.