Code:#include<stdio.h> void main() { int a[]={1,2,3,4,5}; int (*b)[5]; b=a; printf("%u %u %u\n",b,*b,*b[0]); printf("%u %u %d",sizeof(b),sizeof(*b),*b[0]); } o/p: 1000 1000 1 4 20 1
Code:#include<stdio.h> void main() { int a[]={1,2,3,4,5}; int (*b)[5]; b=a; printf("%u %u %u\n",b,*b,*b[0]); printf("%u %u %d",sizeof(b),sizeof(*b),*b[0]); } o/p: 1000 1000 1 4 20 1
b is of type "pointer to an array of five int". *b is of type "array of five int".
If *b is of type "array of five int" ,then Is any extra array getting created for this purpose?
No array is created -- when you set a pointer, the idea is that you are pointing it at something.
You may want to take a look at Prelude's tutorial on pointers. It should answer most of your questions.
If no extra array is created, then how can we say *b is of type "array of five int"...? Is that the property it is holding??
That's why it is of type "array of five int". As in it is the declaration of what kind of object it is. Read the link I posted for you.
Remember, b is of type "pointer to array of 5 ints", so *b is of type "array of 5 ints". Just like with int *p, p is of type "pointer to int" and *p is of type "int". You're dereferencing the pointer when you put that * in front of it, so the resulting type is whatever is pointed to.
EDIT: And remember, you set b to point to a, so dereferencing it doesn't create an array, but it does yield the array pointed to by b
The type of a variable (b, in this case) is a property of the variable. The value is another property of that variable.
The two do not automatically go together (except in some special circumstances that are not particularly relevant here). That means creating a pointer does not magically create a companion pointee.