Pointer to Pointer

  • Before learning What is the Concept of Pointer to Pointer we suggest You please go through the concept of What are Pointers?
  • "Pointer to an Pointer",This means an Pointer Pointing to an Pointer variable
  • As an Pointer is an variable which stores the address of an variable
  • So, Pointer to an Pointer means a variable which will store the address of an Pointer variable.
  • For example:

void main()
{
    int a = 10; //integer variable
    
    int *p; //Pointer variable
    
    p = &a; //storing address of variable a
    
    
    




  • In Above programs we have declare an integer variable a and assign 10 to it.
  • On the next line we have assign the the address of integer variable to an interger pointer p.
  • Now we will declare an another pointer which will store the address of pointer p

  • int **p_to_p; //declaring the pointer variable 
                  //which will store the address of pointer variable p
        
        
        p_to_p = &p; //assigning the address of variable p
        
    

    Let's print the address and the value of variable a,p , and p_to_P



        printf("\nValue of variable a is %d",a);
        printf("\nAddress of variable a is %u",&a);
    
    
        printf("\nValue in pointer variable p is %d",p);
        printf("\nAddress of pointer variable p is %u",&p);
    
    
        printf("\nValue in p_to_p variable is %d",p_to_p);
        printf("\nAddress of p_to_p variable is %u",&p_to_p);
    

    Output
    Value of variable a is 10
    Address of variable a is 6356748

    Value in pointer variable p is 6356748
    Address of pointer variable p is 6356744

    Value in p_to_p variable is 6356744
    Address of p_to_p variable is 6356740

    Let's see what has happen behind




    Let's understand the concept of declaring and levels of pointer variable




  • Pointer can point only to that pointer variable whose level is less than one as compare to the pointing pointer

  • But ,what meant by level of pointer
    let's understand it .

    Pointer of level one:
    void main()
    {
        int a = 10; //integer variable
    
        int *p; //Pointer of level one
        
        p = &a; //assigning the address of variable a 
                //to a pointer p of level one.
    

    Pointer of level two:
        int **p2; //pointer of level two and 
                //can store address of pointer of level 1
    
        p2 = &p;//assigning the address of pointer of level 1
    

    Pointer of level three:
    int ***p3; //pointer of level three and 
              //can store address of pointer of level 2
              
        p3 = &p2;//assigning the address of pointer of level 2
        
    

    Pointer of level Four:
    int ****p3; //pointer of level four and 
              //can store address of pointer of level 3
              
        p4 = &p3;//assigning the address of pointer of level 2
        
     }
    

    • This is what levels of pointer variable means.
    • let's recap it : Pointer can point to a pointer variable only if , its level is less than One as Compare to the level of Pointing pointer.








    Further Concept:




    Further Topics:



    People Also Searched: