Skip to content
UPEEC

Variables and Data Types

A variable is a named place to store a value; its data type decides what values it can hold and what operations make sense.

Beginner
Comments 0

A variable gives a name to a value stored in memory so you can read or change it later.

Common data types:

  • Integer — whole numbers (42, -7).
  • Floating point — numbers with fractions (3.14). Stored approximately, so 0.1 + 0.2 is not exactly 0.3.
  • Boolean — true / false.
  • Character / string — text.

Languages are either statically typed (C, C++, Java — types are checked before running) or dynamically typed (Python — types are checked while running).

int count = 10;        // C: the type is declared
float voltage = 3.3f;
count = 10             # Python: the type comes from the value
voltage = 3.3

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.