C Workshop · Variables and Data Types
Foundation C

Variables and Data Types

A variable is a named box in memory. The type decides the size of the box and how bits are read.

What it is

A variable is a named box in memory. The name is how you find it, the type is the shape of the box, and the value is whatever you last put inside. Until you put something in, you must not trust what is there.

Approach

  1. Pick a type that matches the data (whole numbers → int).
  2. Give the variable a clear name.
  3. Assign before you read it.
  4. Print with a matching format: %d for int, %f for float, %c for char.

Where this is used in the real world

Diagram

Each box is a variable. The label is the name. The number inside is the current value.

42int n
3.5float x
Achar ch

Run algorithm

Each step highlights the matching C line. Program output appears only when a line that prints actually runs.

Ready
C code
1#include <stdio.h>
2int main(void) {
3  int n = 42;
4  printf("%d\n", n);
5  return 0;
6}
What this line does
Press Run algorithm. The highlight will move through the C code.
Program output
(no output yet)

Check your understanding

Five questions. Pick one answer each, then Check answers. The correct choice turns green.

1. A variable is best described as:

Name + storage + type.

2. int n = 42; does what?

Initialize at declare time.

3. Which format prints an int?

%d is decimal int.

4. Why do types matter?

Size and interpretation.

5. Using n before you assign it is:

Garbage until assigned.