Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Array of Pointers

Till now we have seen arrays of integer, arrays of character, arrays of float values, etc.
In the same way, it is also possible to create an array of pointers.
An array, whose all the elements are pointers is known as an array of pointers.
That is every element of this array contains the address of another variable.

Syntax

data_type  *array_name[size];

Example
C Programming Language variables stored in memory in Pointer image4

#include <stdio.h>
int main()
{
    int i=10, j=20, k=30, m=40;
    int *ptr[4];
    ptr[0]=&i;
    ptr[1]=&j;
    ptr[2]=&k;
    ptr[3]=&m;
    printf("\n Address of i = %d",ptr[0]);
    printf("\n Address of j = %d",ptr[1]);
    printf("\n Address of k = %d",ptr[2]);
    printf("\n Address of m = %d",ptr[3]);
    printf("\n");
    printf("\n Value of i = %d",*ptr[0]);
    printf("\n Value of j = %d",*ptr[1]);
    printf("\n Value of k = %d",*ptr[2]);
    printf("\n Value of m = %d",*ptr[3]);
    return 0;
}

Output

Address of i = 1000
Address of j = 5000
Address of k = 2000
Address of m = 3000

Value of i = 10
Value of j = 20
Value of k = 30
Value of m = 40

 

Leave a reply