Core Module
12 min forge

C++ Data Types

Understanding primitives, modifiers, and memory allocation for variables.

C++ Data Types

πŸ“˜ What is it

C++ is a strongly typed language. Data types are used to tell the compiler which type of data a variable will hold, which determines the size and layout of that variable's memory.

⚑ When to use

Always! Every variable in C++ must have a type.

🧠 Time complexity

  • Access: $O(1)$
  • Assignment: $O(1)$

πŸ’» Code example

cpp Standard
int age = 25; // Integer float temp = 98.6f; // Floating point double pi = 3.14159; // Double precision char grade = 'A'; // Character bool isCracked = true; // Boolean

❌ Common mistakes

  • Overflow: Storing a value larger than the type can hold.
  • Precision loss: Using float when double is needed for high accuracy.
  • Mixing signed and unsigned types in comparisons.