Pointer to an array in C.

 

01  #include<stdio.h>
02
03 int main()
04 {
05 int arr[10]={10,20,30,40,50,60,70,80,90,100};
06
07 int i;
08
09 int *ptr; //integer pointer
10
11 ptr= arr; // ptr points to base address of arr (first element)
12
13 for(i=0;i<10;i++)
14 {
15 printf("Value of arr[%d] : %d n",i,*ptr);
16
17 ptr++; // pointer points to next element
18 }
19
20 return 0;
21 }
 
 OUTPUT:

Value of arr[0] : 10
Value of arr[1] : 20
Value of arr[2] : 30
Value of arr[3] : 40
Value of arr[4] : 50
Value of arr[5] : 60
Value of arr[6] : 70
Value of arr[7] : 80
Value of arr[8] : 90
Value of arr[9] : 100

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *