int · 4 bytesdouble · 8 bytescharboolint · 4 bytes1int age = 30;2age = age + 1;3double price = 2.5;4char grade = 'A';5bool ok = true;6int half = 7 / 2;7age = "hi";3030312.5'A'true3!
Violet card: your code; khaki tokens: values moving into variablesSlate boxes: variables in memory, one tick per byte; sand block: the compilerYellow bytes: the size of a type; a red ! for a type errorIn front: the code card (the body of main) and the compiler. At the back: memory, one box per variable, as wide as its type's size in bytes. Each declaration makes a box and a value token hops into it: age gets 30, then 31; price 2.5; grade 'A'; ok true; half 3, because 7 / 2 with two ints drops the .5. The compiler knows every variable's type before the program runs, so age = "hi"; stops the build with a type error. Sizes are those of today's common desktops and phones (64-bit Windows, Linux and macOS on x86-64 or ARM). The standard fixes only sizeof(char) at 1 and sets minimums: int has at least 16 bits. Check your own system with sizeof.

Making variables

  1. A variable is a named box in memory that holds one value. int age = 30; makes a box called age, of type int (a whole number), and puts 30 in it. First the type, then the name, then the value.

More types

Checked by the compiler

What happens

;; step 1/9 · declare
int age = 30;
  int    the type: whole numbers
  age    the name you use from now on
  = 30   the starting value
  ;      every statement ends with ;

Sizes are those of today's common desktops and phones (64-bit Windows, Linux and macOS on x86-64 or ARM). The standard fixes only sizeof(char) at 1 and sets minimums: int has at least 16 bits. Check your own system with sizeof. The drawing lines the boxes up in a row. Where each variable really lives in memory is up to the compiler, which may reorder them or keep some only in CPU registers.