## Array of pointers

Like array of variables, we can declare array of pointers in c where each pointer further points to another array. Code is given below

int a[3= {4,7,8};
int b[4= {7,12,34,2};
int x = 10;
int *ptr[3= {a,b,&x};

In above lines, two int arrays are declared and initialized and one variable x is declared. In last line, an array of pointers is declared and initialized with two const pointers (names of two int arrays) and memory address of variable x using & operator.

Using this array of pointers we can access all elements of any array. Below code will display output as memory address of first element of both arrays respectively and value of x variable because array name contains the memory address of first element.

cout<<a<<b<<x;

We can also get above code output using ptr as

cout<<ptr<<ptr<<ptr;

ptr means first element of pointer's array which is name of first int array.
ptr means second element of pointer's array which is name of second int array
ptr means third element of pointer's array which is memory address of variable x

If we simply use dereference operator with all, we will go to the particular value as

cout<<*ptr<<*ptr<<*ptr;

*ptr will show value of first element of first array
*ptr will show value of first element of second array
*ptr will show value of variable x

## For this increment pointer to jump to next element as below line gives memory addresses of all elements of first array

cout<<ptr;
cout<<ptr+1;
cout<<ptr+2;

ptr is memory address of first element of first array
ptr+1 is memory address of second element of first array
ptr+2 is memory address of third element of first array

And by dereferencing all above we get values of all elements of first array
cout<<*(ptr);
cout<<*(ptr+1);
cout<<*(ptr+2);

*(ptr) gives value of first element of first array
*(ptr+1) gives value of second element of first array
*(ptr+2) gives value of third element of first array

Similarly we can get addresses and values of all elements of second array as below
cout<<ptr;
cout<<ptr+1;
cout<<ptr+2;
cout<<ptr+3;

cout<<*(ptr);
cout<<*(ptr+1);
cout<<*(ptr+2);
cout<<*(ptr+3);

Below is a C++ Program in which an array of pointers c++ is used to manipulate two arrays and one variable Array of pointers in C/C++
Output Array of pointers in C output