&a
is of type int (*)[10]
(which acts like a pointer to an array)
a
is of type int [10]
(which acts like a pointer to a single element)
So when you add 1 keep those types in mind. The pointer will be offset by the size of the type that the address contains. a+1
offsets by the size of int, i.e. to the second element in the array. &a+1
offsets completely past the whole array.
Here address of A=1000(assume) and size of integer=2B.
i) int *p=&A[0][0];
p is pointer it stores the address of A[0][0].it is nothing but starting element address which is equall to A.
ii) int *q=(int*)(&A[0]+1);
q is a poinetr it stores address of A[1].
A[0] it means select the 1st dimension array +1 means skip 1 dimension=A[1].
iii) int *z=(int*)(&A+1)
it skips entire Array.
z stores outside value,1024( Array address 1000-1022)
iv) int *w=(int*) A. it stores Address of array A.
printf:*(p+1)=skip one element in forward direction. so it access A[0][1]=2.
printf:*(q-2)=skip two elemnts in backward direction.so it access A[0][2]=3
printf:*(z-2)=skip two elements in backward direction.so it access A[2][2]=10
printf:w=it is nothing but address of A,varies from different compilers(Garbage value)
but we consider in this problem Address of A=1000,so w=1000.
printf:*(w+1)=same as *(p+1)=2.
so final printed values are 2,3,10,1000,2