What is the difference between an array of a pointer and a pointer to an array with an example?

In  Array is a collection of similar data items, whereas

Pointer is a special kind of Variable that can hold the address of another variable.

So, array of pointer means an array whose contents/data items are pointers.

Suppose,

int *a=&x;

int *b=&y; 

int *c=&&z;

[ Here a,b,c are 3 int type pointer who are holding address of 3 integers x,y and z]

Now, int M[10]; (M is an int array i.e can hold int data elements and is of size 10).

so, M[10]={a,b,c}; ——-> This is Array of pointers, i.e the array is holing a number of pointers .

Where as suppose we have created a new pointer of int type and we are initializing it with the previously created array’s address i.e address of a, like

int *S=a;

So, this is pointer to an array, i.e the pointer is pointing to an array.

Comments

Popular posts from this blog

proassignment help backlink data index 41

Programming shark backlink data index 67

programming shark backink data index 31