Double pointer

sAksham-Ar published on
1 min, 170 words

Categories: C++

We use double pointer or pointer to a pointer for things like dynamically declaring 2d arrays where we first dynamically declare its rows as 1d arrays and then for each row we declare its columns.The name of pointer points to address of the first row or to the pointer that points to first element of the first row.One * with the pointer points to the address of the first element of the first row and with two * it points to its value.

using namespace std;
int main()
    int **a,m,n,i;
    cout<<"Enter rows:\n";
    cout<<"Enter columns:\n";
    a=new int*[m];
        a[i]=new int[n];
    cout<<"Address of first row:"<<&a[0]<<" and "<<a<<"\n";
    cout<<"Address of first elment of first row:"<<&a[0][0]<<" and "<<*a<<'\n';
    cout<<"Value of first element of first row:"<<a[0][0]<<" and "<<**a<<'\n';
    return 0;