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 Standardint 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
floatwhendoubleis needed for high accuracy. - Mixing signed and unsigned types in comparisons.