The way an array of integers or an array of floating point numbers can be declared, in the similar way an array of pointers can also be declared. Since a pointer holds the address of a variable, an array of pointers will hold the collection of addresses. The address stored in the array of pointers can be addresses of isolated variables or addresses of array elements or any other addresses. All rules that apply to an ordinary array also apply to the array of pointers. The array of pointer can be declared by preceding an asterisk to an array. For example,
int *ptr [10];
Program - array of pointers
#include<stdio.h>
#include<conio.h>
void main ()
{
int arr [5] = {10, 15, 20, 25, 30};
int *ptr [5] = {arr, arr+1, arr+2, arr+3, arr+4};
int i;
clrscr ();
for (i = 0; i<5; i++))
printf (“Address %u Address %u value %d\n”, *(ptr+i), &arr [i], arr [i]);
getch ();
}
Output
Address 6684132 Address 6684132 Value 10
Address 6684134 Address 6684134 Value 10
Address 6684136 Address 6684136 Value 10
Address 6684138 Address 6684138 Value 10
Address 6684140 Address 6684140 Value 10
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc