Pointer to Pointer in C - Pointer to Pointer (Double Pointer)



 pointer to pointer

Learn C - C tutorial - pointer to pointer - C examples - C programs

Pointer to Pointer (Double Pointer)

  • A pointer points to a location in memory and used to store address of variables. So, when we define a pointer to pointer. The first pointer is used to store the address of second pointer ie. Called as double pointers.

How to declare a pointer to pointer in C ?

  • Declaring Pointer to Pointer is similar to declaring pointer in C. The difference is to place an additional ‘*’ before the name of pointer.
 pointer to pointer

Learn C - C tutorial - pointer to pointer - C examples - C programs

Syntax


int **ptr;    // declaring double pointers

Sample Code

#include <stdio.h>
int main()
{
    int a=10; //normal variable
    int *ptr_a;//pointer variable
    ptr_a = &a;
    int **ptr_ptra; //pointer to pointer
    ptr_ptra = &ptr_a;
    printf("Value of a: %d\n",a);
    printf("Value of a using pointer: %d\n",*ptr_a);
    printf("Value of pointer to pointer: %d\n",**ptr_ptra);
    return 0;
}

Output

Value of a: 10
Value of a using pointer: 10
Value of pointer to pointer: 10


View More Quick Examples


Related Searches to Pointer to Pointer in C - Pointer to Pointer (Double Pointer)