Pointer to pointer in c

Preview
You must first complete Introduction to pointer in C | pointer operations in C before viewing this Lesson

Pointer to pointer

C language allows us to take pointer variables which can contain address of other pointer variables. In such a case, the concept of pointer to pointer is used. The pointer to pointer variable can be declared by prefixing the variable declaration with double asterisk sign.
Example
int **a;
Here, pointer variable a is pointer to pointer variable as it is prefixed with two asterisk signs.



Program to demonstrate pointer to pointer.
#include<stdio.h>
int main()
{int a=10,*b,**c;b=&a;
c=&b;printf(“\nb=%u”,b);
printf(“\n*b=%d “,*b);
printf(“\n*c=%u”,*c);
printf(“\n**c=%d “,**c);

return(0);
}

Output
b=65524
*b=10
*c=65524
**c=10
Description
In the above program, c is pointer to pointer variable and it contains the address of other pointer variable b which further contains the address of normal variable a.
*b refers to the value of a.
*c refers to the address of a.
**c refers to the value of variable a.



Best Books of C





Lesson tags: pointer to pointer, program of pointer to pointer in c
Back to: C Programming Language