Pointer to array in C ?


A pointer variable can store address of other variable . Not only can a pointer store the address of a single variable, it can also store the address of cells of an array.

Example:-

int arr[5];
int *p;
p=arr;
Here, p is a pointer variable, and arr is an array. When code p=arr will be excuted p stores the address of the first elements of array in variable p; We can write, p=arr or p= &arr[0] both are same.

Q) W.A.P to initialize pointer to array
 #include<stdio.h>
 void main()
 {
 int arr[5],i;
 int *p;
 p=arr; 
 for(i=0;i<=4;i++)
 {
 printf(“Enter  no”);
 scanf(“%d”,&arr[i]);
 }
 for(i=0;i<=4;i++)
 {
 printf(“%d\n”,*p);
 *p++;
 }
 getch()
 }
Output
enter no:
6
7
34
23
8