Keep going around circles, but I am still unclear about this. Have a feeling about the answer; but not sure. Which code below consumes more memory? [Should be the former, if I am correct.]
double x;
double* y = new double(x);
OR
double x;
double* y = &x;
In the former, two
doubles exist (x, and the one pointed to byy).xis allocated on the stack, andyon the heap.In the latter, only one
doubleexists (x, also pointed to byy). There are no heap allocations involved here.So, on the face of it, you are correct.
In both cases, there exists one
doubleon the stack, and onedouble*also on the stack. The difference between the two is that in the first case, there is also adoubleallocated on the heap (the one allocated bynew double(x)). Therefore the first case requires more storage.