Is it possible to have variables that don't end up with its own memory?
The C++ standard allows the C++ compiler to perform any optimization that has no observable effects.
If your C++ compiler can prove to itself that, for your example, using b
as a mere alias for a
will have no observable effects, then it is permitted, but not obligated, to compile this optimization which will have the effect of b
not existing at all and not using any memory; and all references to b
actually using a
.
But you have absolutely no way to know that, except via external means such as using an external debugger, perhaps. If you had a way to know that, in the context of the C++ program, then, of course, making this optimization would have an observable effect and your C++ compiler will not do that.