The problem when you do something like &&a;
is that you're asking for "the address of the address of a
".
That doesn't make sense. We can get the address of a
just fine, but that doesn't give us a variable we can take the address of. It just gives us a pointer value. Until that value is stored somewhere, we can't take its addres.
If you have code such as 2+2
, the result doesn't have an address either. It is just the value 4, but it hasn't yet been stored anywhere, so we can't take an address. Once we store it into an int
variable, we can take the address of that variable.
Basically, the problem is the difference between values and variables. A value is just a number (or a character, or some other data). A variable is a place in memory where a value is stored. A variable has an address, but a value doesn't.
In C++-speak, it is the difference between rvalues and lvalues. An rvalue is essentially a temporary, it's typically a value that was returned from another operation (such as the &
operator in your case), but which hasn't yet been stored anywhere.
Once you store it into a variable, you get a lvalue, and lvalues have an address you can take.
So yes, you need the two separate statements. First you take the address, and then you store that address somewhere. And then you can take the address of this "somewhere".