Memory allocated with new
is on the HEAP, everything else in on the stack. So in your code, you have
vehicle* motorVehicle[2] = { new (car), new (motorcycle) };
On the stack there is an array of two pointers vehicle*[2]
, and on the heap are two objects, a car
and a motocycle
.
Then you have two loops
for (int i = 0; i < 2; i++)
each of which create an integer on the stack for the duration of the loop.