C Programming Arrays of Pointers

Array of pointers in C can be declared like an array of integers or character. An array of pointers is a collection of pointer variables stored in continuous memory location. In other works, it is an array of addresses. Each element of a pointer array is bound to store address of same data type. Here is the syntax of declaring an array of pointers.

data_type *identifier[size];
For Example
int *array_ptr[100];

Array 'array_ptr' is an array of pointer of size 100, where each array element can store the address of integer variable. All array arithmetic holds good with array or pointers also. Here is an example of array of integer pointers.


C Program to show the use of Array of Pointers

#include <stdio.h>
#include <conio.h>

void main() {
    int *ptr_array[6];
    int a1=1, a2=2, a3=3 ,a4=4, i;
    int int_array[] = {10, 20};    

    /* Assigning addresses of individual variables */
    ptr_array[0] = &a1;
    ptr_array[1] = &a2;
    ptr_array[2] = &a3;
    ptr_array[3] = &a4;
    
    /* Assigning addresses of integer array elements */
    ptr_array[4] = &int_array[0];
    ptr_array[5] = &int_array[1];
    
    /* Printing the integer values in addresses stored in ptr_array*/
 for(i=0; i<6; i++) {
        printf("%d\n", *(ptr_array[i]));
    }
    
    getch();
    return 0;
}

Program Output
1 
2 
3 
4 
10 
20