250 views
0 votes
0 votes
What is the main difference between array of pointers and pointer to an array? please Explain with the help of a program/example
 

1 Answer

Best answer
1 votes
1 votes

array of pointers : 

int *a[4];

We know that pointer holds a address of int data type variable. So the above mentioned a[] can store four different  int data type address i.e. a[0], a[1], a[2], a[3]. each can hold a int data type address.
For example:
int a1;
int a2;
int a3;
int a4;

So we have four different variable which are of type int so we can assign these to the above declared a[] 
i.e.int a[0] = & a1

This is similar to declaring four different int pointers but instead we used an array to hold these four pointers

Pointer to array : 
int ( *a)[4];   

In simple language the "a " is a single variable that holds the address of the array. 

Example:
int simple_array[4];
Now we can assign 
a = simple_array; or
a = & simple_array[0];

selected by

Related questions

0 votes
0 votes
2 answers
1
iarnav asked May 27, 2017
496 views
What is meant by precedence rule for evaluation of expressions?
0 votes
0 votes
1 answer
2
iarnav asked May 27, 2017
247 views
What are structured languages and what are their major features?
0 votes
0 votes
1 answer
3
iarnav asked May 27, 2017
273 views
Consider a pointer declaration int i=10,*p; p=&x;Is p – – ; a valid statement, justify? explain in as simple way as possible.
0 votes
0 votes
0 answers
4
iarnav asked May 27, 2017
178 views
how to Write a program to search a key string in a array of strings,if a key string is found then return its position and then replace that key string by any string using...