Variables and Memory

A variable is a named box in memory that holds a value of one type.

The idea

Think of a row of lockers. Each locker has a name on the door (the variable name), something inside (the value) and a locker number (its memory address). age := 30 says “grab a free locker, label it age, put 30 inside”.

When you write other := age, Go photocopies what is inside into a new locker. Changing the copy never changes the original. Almost everything in Go works this way: assignment copies the value.

Watch it work

Try it

Common mistakes