C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Pointers in C

Array of pointers

C Program: Array of Pointers

C

#include <stdio.h>

 

int main() {

    int a = 10, b = 20, c = 30;

    int *arr[3];   // Array of integer pointers

 

    // Assign addresses to pointer array elements

    arr[0] = &a;

    arr[1] = &b;

    arr[2] = &c;

 

    // Display values using pointer array

    printf("Values stored in variables using pointer array:\n");

    for (int i = 0; i < 3; i++) {

        printf("Value of variable %d = %d\n", i + 1, *arr[i]);

    }

 

    return 0;

}

Output

 
OUTPUT :
Values stored in variables using pointer array:
Value of variable 1 = 10
Value of variable 2 = 20
Value of variable 3 = 30

Explanation

  • arr is an array of pointers to integers (int *arr[3]).
  • Each element of arr stores the address of an integer variable (a, b, c).
  • You can access the actual value using the dereference operator (*).
  • The loop prints the values pointed to by each element in the pointer array.