Pointer to an array
Pointer To An Array
/*Pointer to an Array
>> Show contents of an Array using pointer
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10]={10,20,30,40,50,60,70,80,90,100};
int i;
int *ptr; //integer pointer
ptr= arr; // ptr points to base address of arr (first element)
for(i=0;i<10;i++)
{
printf("Value of arr[%d]: %d\n",i,*ptr);
ptr++; // pointer points to next element
}
getch();
}
/*
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
*/
Download Now
Comments
Post a Comment