CPP Data Types

💻 C++ Data Types (CPP Data Types) – Complete Beginner to Interview Guide
Data types in C++ specify what type of data a variable can store.
They decide:
how much memory is used
what kind of values are allowed
what operations can be performed
1️⃣ What is a Data Type? ⭐
A data type tells the compiler the type and size of data a variable will hold.
Example
📌 int is the data type of variable age.
2️⃣ Types of Data Types in C++ ⭐⭐
C++ data types are mainly divided into 4 categories:
Basic (Primitive) Data Types
Derived Data Types
User-Defined Data Types
Void Data Type
3️⃣ Basic (Primitive) Data Types ⭐⭐⭐
int
Stores whole numbers.
📌 Size: usually 4 bytes
float
Stores decimal numbers (less precision).
📌 Size: 4 bytes
double
Stores decimal numbers (more precision).
📌 Size: 8 bytes
char
Stores a single character.
📌 Size: 1 byte
bool
Stores true or false.
📌 Size: 1 byte
string
Stores text (sequence of characters).
📌 Requires #include <string>
4️⃣ Derived Data Types ⭐⭐
Derived from basic data types.
Array
Pointer
Reference
5️⃣ User-Defined Data Types ⭐⭐
Created by the programmer.
struct
union
enum
typedef / using
6️⃣ Void Data Type ⭐
Represents no value.
📌 Used with functions that do not return anything.
7️⃣ Size of Data Types ⭐⭐
📌 Size may vary depending on system/compiler.
8️⃣ Type Modifiers ⭐⭐
Used to modify basic data types.
shortlongsignedunsigned
Example
9️⃣ Common Data Type Errors ❌
❌ Using wrong data type
❌ Data overflow
❌ Forgetting to include <string>
❌ Assuming same size on all systems
📌 Interview Questions (CPP Data Types)
Q1. What is a data type?
👉 Specifies type of data a variable can store
Q2. Difference between float and double?
👉 Precision and size
Q3. What is void data type?
👉 Represents no value
Q4. Which data type stores true/false?
👉 bool
✅ Summary
✔ Data types define type & size of data
✔ Categories: Basic, Derived, User-defined, Void
✔ Choose correct data type for efficiency
✔ Important for memory & performance
