C Program to Display Array Elements Using Pointer to Array

In this program, you'll learn to display array elements using pointer to array. The pointer is a variable which stores the address of another variable. This variable can be of type int, char, array, function, or any other pointer. The size of the pointer depends on the architecture. However, in 32-bit architecture the size of a pointer is 2 byte. Unlike other variables that hold values of a certain type, pointer holds the address of a variable. For example, an integer variable holds (or stores) an integer value, however an integer pointer holds the address of a integer variable. Pointer to an array is also known as array pointer. We are using the pointer to access the components of the array. int a[3] = {3, 4, 5 }; int *ptr = a; We have a pointer ptr that focuses to the 0th component of the array.

Source Code
void main()
    int *ptr[5], i;
    int arr[] = {11,22,33,44,55};
    for(i=0; i<5; i++)
        ptr[i] = &arr[i];
    /* Display elements using pointer to array */
    printf("Elements of array are :\n");
    for(i=0; i<5; i++)
        printf("%d ", *ptr[i]);
Elements of array are :
11 22 33 44 55

"Coding Hub - Learn to code" app now available on Google Play Store