Learn VisualLearn CS

How Variables and Types Work

A variable is a location reserved in memory to hold a value. Variables have types, such as int for a whole number or char for a single character, and the type determines how many bytes of memory that variable uses. Variables are laid out one after another in memory, so changing the size of any one variable shifts the address of every variable placed after it.

GOAL

Explain how a variable's type determines its size in memory, and how that shifts the addresses of the variables that follow.

If a is an int at 4 bytes and b is a char at 1 byte, how far is b's address from a's address?