Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Pointer to Array

Pointer pointing to the complete array is known as a pointer to array.

Syntax of pointer to an array

data_type  (*pointer_name)[array_size];

For better understanding let’s see how both the normal pointer and pointer to array, points to the array.

C Programming Language Difference between Normal Pointer and Pointer to an Array

Example

#include <stdio.h>
int main()
{
    int arr[5]={10,20,30,40,50};
    int *ptr1;  // normal pointer variable
    int (*ptr2)[5]; // pointer to an array of size 5
    ptr1=&arr;
    ptr2=&arr;
    printf("\n ptr1 points to = %d",ptr1);
    printf("\n ptr2 points to = %d",ptr2);
    ptr1++;
    ptr2++;
    printf("\n After increment ptr1 points to = %d",ptr1);
    printf("\n After increment ptr2 points to = %d",ptr2);
    return 0;
}

Output

ptr1 points to = 2293280
ptr2 points to = 2293280
After increment ptr1 points to = 2293284
After increment ptr2 points to = 2293300

 

Leave a reply