Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize pointer to pointer using multiple address operators in C or C++

Tags:

c++

c

It just occurred to me That I don't know how to initialize a pointer to pointer from a non pointer value with one statement in C++:

int a = 1;
int** ppa = &&a; //Does not compile
int** ppa = &(&a); //Does not compile
int* pa = &a;   //Works but is a
int** ppa = &pa; //Two step solution

Am I missing something, is the two statement the one and only way to do it?

like image 332
David Reis Avatar asked Sep 28 '10 07:09

David Reis


Video Answer


1 Answers

if you want a pointer to a pointer, the pointer that you want to point to must be located somewhere in memory, so I think there cannot be a "one step solution" because you need a pointer variable that you can point to.

(Note: This sentence is not meant to be a linguistic trial to use "point" as often as possible in one sentence :-))

like image 179
Philipp Avatar answered Oct 03 '22 07:10

Philipp