Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Pointer variable holds the address of another Pointer Variable?

Tags:

c++

c

pointers

Is it possible to make a pointer variable hold the address of another pointer variable? eg:
int a; int *ptr,*ptr1; ptr=&a; ptr1=&ptr;

like image 647
sandbox Avatar asked Dec 10 '22 03:12

sandbox


1 Answers

Sure, a pointer to a pointer.

int i;
int *pi = &i;
int **ppi = π

There is nothing particularly unusual about a pointer to a pointer. It's a variable like any other, and it contains the address of a variable like any other. It's just a matter of setting the correct type so that the compiler knows what to do with them.

like image 108
Jonathan Wood Avatar answered Dec 31 '22 01:12

Jonathan Wood