Double Pointer (pointer to pointer)

A pointer to a pointer is a form of multiple indirection or chain of pointers and pointer contains the address of variable. First pointer store the address of the variable and the Second variable is used to store the address of the first pointer. That’s why we know as Double pointer. Let’s see the diagram given below

The Syntax of declaring a double pointer is given below

int**p;

Consider the following example

#include<stdio.h>  
void main ()  
{  
    int a = 10;  
    int *p;  
    int **pp;   
    p = &a;   
    pp = &p;
    printf("address of a: %x\n",p);    
    printf("address of p: %x\n",pp);   
    printf("value stored at p: %d\n",*p); 
    printf("value stored at pp: %d\n",**pp);  
}

Output

address of a: d26a8734
address of p: d26a8738
value stored at p: 10
value stored at pp: 10

Double pointer example

Let’s see the example where one pointer to the address of another pointer

#include<stdio.h>  
int main(){  
int number=50;      
int *p;  
int **p2;      
p=&number;      
p2=&p;    
printf("Address of number variable is %x \n",&number);      
printf("Address of p variable is %x \n",p);      
printf("Value of *p variable is %d \n",*p);      
printf("Address of p2 variable is %x \n",p2);      
printf("Value of **p2 variable is %d \n",*p);      
return 0;  
}

Output

Address of number variable is fff4
Address of p variable is fff4
Value of *p variable is 50
Address of p2 variable is fff2
Value of **p variable is 50

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

The Technical Funda
Average rating:  
 0 reviews