Concept of Pointer(Part-2)

//pointer2
#include<stdio.h>
void main()
{
int *p[10]; //it is an array of 10 pointers that is there are 10 pointer declared here.
int (*q)[10];  //it is a single pointer which points an array of integer.that is q points                       the base address of array
int a[10]={0,1,2,3,4,5,6,7,8,9};
                           // p=&a //this line show error because p is an array. That is                                   multiple variable but &a means the base address(a single                                      variable) of array a[10] that is a[0]. Hence,multiple                                                value=single value is invalid.
p[0]=&a[0];
p[1]=&a[1];
p[2]=&a[2];
q=&a;                   //it points the base address of array a. so the q=&a[0]
printf("%d\t%d\t%d\t%d\t%d\t%d",p[0],p[1],p[2],q,&a[0],&a);
}

Comment is enough for explanation of the above program. if arise any confusion, can comment in comment section. Hope you understand.

 

Leave a Reply

Your email address will not be published.