• Register

An array of pointers is an indexed set of variables which act as pointers i.e. referencing a location in the computer's memory or addressing some other element. The relevance of such pointers is to enhance creation, use and destroying all types of data structures.

 

Example

For instance, if an array of pointer holding 5 integer pointers, the declaration would be:

*ptr[5];//array of 5 integer  pointers.

 

Assume an array of marks that hold 20 values of integer type, then the marks will be addressed by the first element which is marks [0]. This means that array name (marks) holds the first element of an array.

Program

#include <iostream>  

using namespace std;  

int main()  

{  

    int *ptr;  // integer pointer declaration  

    int marks[10]; // marks array declaration  

    std::cout << "Enter the elements of an array :" << std::endl;  

    for(int i=0;i<10;i++)  

    {  

        cin>>marks[i];  

    }  

    ptr=marks; // both marks and ptr pointing to the same element..  

    std::cout << "The value of *ptr is :" <<*ptr<< std::endl;  

    std::cout << "The value of *marks is :" <<*marks<<std::endl;  

}  

As illustrated in the syntax, both integer pointer and array are integers. It addresses marks using ptr=marks which means both “marks “and “ptr” point to the same element. The output of printing ptr and marks will have similar value because an array name stores the address of the first element of an array. 

I hope this helps.

100 points
7 2