Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Allocate a Cube width 20 on the heap, allocate a Cube pointer c on CreateCubeOnHeap's stack to store the address of the Cube.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Deallocate stack memory for CreateCubeOnHeap and return the value of pointer c.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Allocate cube on main's stack and store the returned pointer.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Call method getVolume on cube, which calculates the volume to be 8000.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Allocate double v to store the return value 8000.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Deallocate the Cube pointed by cube, notice that cube is still pointing to invalid memory on heap
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Set the value of cube to nullptr, which is 0.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Deallocate the stack memory of main.