Array
of pointers:-
A
pointer variable can store address of another variable whereas the array of
pointers can store addresses of array elements. The pointer array can be
declared as follows:
Syntax:-
Datatype *variable[size];
Eg.,
int
*ap[10];
i.e., it indicates that ap is a pointer array which can store
addresses of 10 elements which are of integer datatype.
Ø A
Program to print elements of an array and their corresponding addresses.
#include<stdio.h>
#include<conio.h>
void main( )
{
int a[5]={1,2,3,4,5},*ap[5],i;
for(i=0;i<5;i++)
ap[i]=a+i;
printf(“the elements are”);
for(i=0;i<5;i++)
printf(“%d is at %u\n”,*ap[i],ap[i]);
getch( );
}
No comments:
Post a Comment