c programming tips and tricks

Pointer to array and Array of Pointers.

Let’s check out an interesting comparison between the following three declarations.

int *ptr1[5];
int (*ptr2)[5];
int* (ptr3[5])
int *ptr1[5];

Here in int *ptr1[5], ptr1 is an array of 5 integer pointers (An array of int pointers).

int (*ptr2)[5];

And in int (*ptr2)[5], ptr2 is a pointer to an array of 5 integers (A pointer to an array of integers).

int* (ptr3[5]);

Leave a Reply

Your email address will not be published. Required fields are marked *