CSCI 221 F20

Solutions to the Practice Midterm #1B

These are my solutions to practice midterm exam B. Below are the C++ source files for Problems 1, 2, 4, and 5.

Below is my diagram of the memory for Problem 3. Rather than drawing pointers, I used made-up addresses for the stack frame and for the heap-allocated data. I decided to have my stack grow downward from address 32767, and my heap data start at address 16384.

main's stack frame

address        data
-------        ----
32764-32767 x: [  11] 4 bytes
32756-32763 y: [   32764] 8 bytes          
32748-32755 z: [   16384] 8 bytes          

...

the heap

16384-16387  : [  10] 4 bytes 

The data region for the bytes of x get set to 6, then updated to 10 when y[0] is changed. Then the 4 bytes in the heap get set to 10. Finally, the bytes of x get updated to 11.