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

  1. Allocate Cube c for CreateCube.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Deallocate stack memory of CreateCube and return address of c.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Allocate pointer c for main and store the returned value. Notice that the stack memory of CreateCube is overwritten.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Allocate stack memory for getVolume and calculate volume using the width of c. Since the width of c is corrupted, the volume is also incorrect.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Deallocate memory of getVolume. Allocate r for main to store the return value of getVolume.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Allocate stack memory for getSurfaceArea and calculate surface area using the width of c. Similar to getVolume, the surface area calculated will be incorrect.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Deallocate memory of getSurfaceArea. Allocate v for main to store the return value of getSurfaceArea.
Source: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/

  1. Deallocate the stack memory of main and return 0