Array of pointers in C Programming
Example: Write a program to assign the address of array elements to pointer variable and print the array element with address.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <stdio.h> int main () { int arr[] = {10, 20, 30}; int i, *ptr[3]; for ( i = 0; i < 3; i++) { ptr[i] = &arr[i]; // assign the address array element to pointer variable } for ( i = 0; i < 3; i++) { printf("\n Value of arr[%d] = %d", i, *ptr[i] ); printf("\n Address of arr[%d] = %d", i, ptr[i] ); } return 0; } |
OUTPUT
1 2 3 4 5 6 | Value of arr[0] = 10 Address of arr[0] = 1392582964 Value of arr[1] = 20 Address of arr[1] = 1392582968 Value of arr[2] = 30 Address of arr[2] = 1392582972 |