Double & Triple pointer in C


Double Pointer

The pointer is a variable which stores the memory address of another variable. So, when we define a pointer to pointer. The first pointer is used to store the address of the variable. And the second pointer is used to store the address of the first pointer. That is why they are also known as double pointers.
      Syntax :
           Data_type **variable_Name ;
      Example :
           int **q ;
                q => This is double pointer variable and not normal variable

Triple Pointer

A triple-pointer is a pointer that points to a memory location where a double-pointer is being stored. The triple-pointer itself is just one pointer. Ex. int *** is a pointer, that points to the value of a double pointer, which in turn points to the value of a single pointer, which points to the value of an int.
      Syntax :
           Data_type ***variable_Name ;
      Example :
           int ***r ;
                r => This is double pointer variable and not normal variable

Source Code

#include<stdio.h>
int main()
{
    int a=10,*p;
    int **q;   // Pointer to Pointer or Double Pointer
    int ***r; //Triple Pointer
    p=&a; //Address of a
 
    printf("\n Value of  A           : %d",a);
    printf("\n Address of  A         : %d",&a);
    printf("\n Value of  P           : %d",p);
    printf("\n Address of  P         : %d",&p);
    printf("\n P Dereferencing       : %d",*p);
    printf("\n------------------------------------");
 
    q=&p;
    printf("\n Value of  P           : %d",p);
    printf("\n Address of  P         : %d",&p);
    printf("\n Value of  q           : %d",q);
    printf("\n Address of  q         : %d",&q);
    printf("\n **Q Dereferencing     : %d",**q);
    printf("\n------------------------------------");
 
    r=&q;
    printf("\n Value of  q           : %d",q);
    printf("\n Address of  q         : %d",&q);
    printf("\n Value of  r           : %d",r);
    printf("\n Address of  r         : %d",&r);
    printf("\n ***r Dereferencing    : %d",***r);
    printf("\n------------------------------------");
 
    return 0;
}
 
To download raw file Click Here

Output

 Value of  A           : 10
 Address of  A         : 6356732
 Value of  P           : 6356732
 Address of  P         : 6356728
 P Dereferencing       : 10
------------------------------------
 Value of  P           : 6356732
 Address of  P         : 6356728
 Value of  q           : 6356728
 Address of  q         : 6356724
 **Q Dereferencing     : 10
------------------------------------
 Value of  q           : 6356728
 Address of  q         : 6356724
 Value of  r           : 6356724
 Address of  r         : 6356720
 ***r Dereferencing    : 10
------------------------------------

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C