C Language



Admission Enquiry Form

  

Pointer to Pointer in C




What is Pointer to Pointer ?

Pointer to pointer is a chain of pointers.Generally, pointer is a special variable which stores the address of another variable ,but of same type. Pointer to pointer means one pointer refers to the address of another pointer. 

Let's understand this concept through an example:As shown above, a is a variable. It has the memory address 65539 and 65539 is stored at the ptr1 (pointer1). ptr1 has the memory address 65518 which is stored in ptr 2(pointer 2).




How to declare a pointer in C programming?


int *ptr1;

How to declare a pointer to pointer in C programming?
int **ptr2;

#include <stdio.h> 
int main() 

int a=5; 
int *ptr1,**ptr2; // *ptr1 is a pointer and **ptr2  is a double pointer. 
ptr1=&a; 
ptr2=&ptr1; 
printf("value of a is:%d",a); 
printf("\n"); 
printf("value of *ptr1 is : %d",*ptr1); 
printf("\n"); 
printf("value of **ptr2 is : %d",**ptr2); 
return 0;