HexLab

Lesson 5

Data Types in C++

An introduction to C++ data types and memory considerations.

Lesson content

Data Types in C++

Data types define the type and size of data that a variable can hold. C++ has built-in data types for integers, floating-point numbers, characters, and booleans.

Integer Types

  • int: typically 4 bytes, range from -2^31 to 2^31-1
  • short: typically 2 bytes, for smaller integer values
  • long: typically 4 or 8 bytes, for larger values
  • unsigned int: for non-negative integers only

Floating-Point Types

  • float: typically 4 bytes, single-precision floating-point
  • double: typically 8 bytes, double-precision floating-point
  • long double: extended precision floating-point

Other Types

  • char: single character, typically 1 byte
  • bool: boolean value (true or false)
  • void: represents the absence of a value

Example Declaration

int age = 25;
double salary = 50000.50;
char grade = 'A';
bool isActive = true;