Monday, 13 March 2017

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;
}

No comments:

Post a Comment