Skip to content

Variables looping and grouping

RAM Memory Representation

In prolog of the previous article we talked about the possibility to create more abstact levels of information once we're sure about simpler ones.
We'll touch with hands how to group variables into structures containing them.
To make things easier please refer to picture, where RAM memory scheme is represented in the simplest logical view.

Every colored box is a location where to put data and as well it has a label assigned by operating system on its startup: progressive numeration is enough for our goals.
It doesn't matter if first box matches the effective first memory location: here we just need to think these boxes contiguous.

What happens when a compiler meets a variable declaration?

It creates a momentary internal relationship between two labels, one from o.s. and the other from our code: for example X is bound to box 1 (the second).
[Notice the numeration starts from zero: this is common in not all but so many programming languages]

Keep in mind an important point: X is associated to the label of box, not directly to its stuff.
When you look through white pages service, you find just an address and a name, but nothing else about who live in that house or what's there.
Indeed operating system labels are called memory address!
Assigning a value to the X variable (X := 1;) we ask the compiler to write that value into the box bound to X.

Well... if everything on single variable is clear, what about those five grouped?
By walking through code will give us the little but complete vision, by keeping on with the previous code.

Let's go!