I thought that if I create a pointer to array type, I will be able to print all of its elements. I wrote a program like this,
#include <stdio.h>
int main()
{
int arr[] = {4,2,3};
//here arr is a (*arr)[3] type
int (*p)[3], i;
p = &arr;
for(i = 0 ; i < 3 ; i++)
printf("%d ", *(p)[i]);
printf("\n");
return 0;
}
output : 4 0 -673566907
My understanding is p will point to an array of 3 elements. p+1 will point to another array of 3 elements.
arr=x [ 1 2 3 ]
y [x] [x+1] [x+2]
p=y(address of arr)
*p=x
**p = 1
*(*p+1) = 2
*(*p+2) = 3
I can print array like above. Does it mean p is actually double pointer?
P.S Is it correct way to read
*(p)[1] should be read as "p is an array of 1 pointer to"
(*p)[1] should be read as "p is a pointer to an array of 1 element"
when we print
printf("%d ", (*p)[1]); //here it should be read as p is a pointer to the second element"