Loading....
Coupon Accepted Successfully!

 

Pointer to Pointer

Pointer to pointer is a pointer that stores the address of another pointer. There can be a chain of pointers depending on applications/requirements. In Figure, x is a simple variable, p is a pointer to the variable x, and q is a pointer to x. The values of variables ‘x,* p, and **q’ are shown in the boxes, and their addresses are shown outside the boxes.
 
29144.png
Fig: Pointer to pointer
 
The program on pointer to pointer is as follows:

 

13.6 Program to demonstrate the concept of pointer to pointer.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int x=10;

int *p;

int **q;

p=&x;

q=&p;

cout<<“\n Value of x =”<<x;

cout<<“\n Value of x = ”<<*p;

cout<<“\n Value of x = ”<<**q;

cout<<“\n Adderss of x ”<<unsigned(*q);

cout<<“\n Adderss of x ”<<unsigned(p);

cout<<“\n Adderss of x ”<<unsigned(&x);

cout<<“\n\n Adderss of p ”<<unsigned(&p);

cout<<“\n Adderss of p ”<<unsigned(q);

cout<<“\n Adderss of q ”<<unsigned(&q);

}

OUTPUT

Value of x =10

Value of x = 10

Value of x = 10

Adderss of x 65524

Adderss of x 65524

Adderss of x 65524

Adderss of p 65522

Adderss of p 65522

Adderss of q 65520

 

Explanation: In the above program, the value of x is initialized as 10. The same value is displayed with the first three cout statements. p holds the address of x, q holds the address of p, and the same are displayed using pointers.





Test Your Skills Now!
Take a Quiz now
Reviewer Name