Click here for the Spring 2026 website CS111 - Lab 7: Part 3. Memory Diagrams from Code

Lab 7: Part 3. Memory Diagrams

Why Memory Diagrams?

Aliasing is when the same memory location can be acccessed using different variable names. In other words, aliasing occurs when two different variables point to the same location in memory. The best way to see and understand this is by drawing memory diagrams.

Prefer a digital version of these tasks? Click here and make a copy.

Task 1.

Below is a snippet of code. Write the output that is generated by the print statements.

a = [2, 4, 6]
b = [1, 3, 5]
b[2] = a[0] * a[1]
a.insert(1,'water')
print('---- 1st print ----')
print(a)
print(b)
a = b
print('---- 2nd print ----')
print(a)
print(b)
b.pop()
b.append('blue')
print('---- 3rd print ----')
print(a)
print(b)

Table of Contents