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

A pointer variable in C language can also contain address of another pointer variable. This concepts is called pointer to pointer. We can declare a pointer to pointer as:
int **ptr;
Here, ptr is a pointer to pointer.

Program of pointer to pointer.
#include<stdio.h>
int main()
{

int var1=20,*var2,**ptr;

var2=&var1;

ptr=&var2;

printf(“\n*ptr=%u”,*ptr);
printf(“\n**ptr=%d “,**ptr);

return(0);
}

Output
*ptr=65524
**ptr=10
Description
In the above program, ptr is pointer to pointer. It contains address of aother pointer variable var2 which contains the address of variable var1.
*var2 refers to the value of var1.
*ptr refers to the address of var1.
**ptr refers to the value of variable var1.



Best Books of C





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