Base CS from zero
Data in memory: multiple-choice review
Six questions that cut across the whole unit. None of them asks you to recite a definition — each asks you to reason about how data actually sits in memory and why the layout behaves the way it does.
Confirm you can connect the four ideas the unit built: equal-size contiguous cells, the index-to-address formula, named-field objects, and references that let a fixed grid hold variable-size things.
An array of 8 numbers occupies one contiguous block of 32 bytes. Which statement about its layout is correct?
Reaching arr[3000] takes the same time as reaching arr[3]. Why is array access constant time?
Why is the first element of an array at index 0 rather than index 1?
An array reaches a value by arr[2]; an object reaches a value by user.age. What is the core difference, and what follows from it?
You have an array of 100 user objects, each a different size. How does it sit in memory while keeping the array's equal-size contiguous grid?
Reading users[1].name in an array of objects takes two hops. What are they, and why two?
The through-line of the unit is one layered picture. An array is a contiguous run of equal-size cells, so any element’s address is one multiply and one add (base + i x element_size) — constant time, with index 0 forced by a zero offset. An object groups values by name instead of position, so its field order carries no meaning. And because a fixed-size cell cannot hold a variable-size object, cells hold references — equal-size addresses — letting a uniform grid point at variable-shape data elsewhere. Carried all the way, nested data is a graph of cells: some holding values, some holding addresses, wired together.