Data Types in C++
Aim To understand and explore various primitive data types in programming, with a focus on their usage in C++.
Theory Primitive data types are the fundamental building blocks of any programming language. In C++, they are used to store and manipulate basic forms of data such as numbers, characters, and logical values.
Common Data Types in C++
Data Type | Description | Example |
---|---|---|
int |
Stores whole numbers without decimals | int marks = 25; |
float |
Stores single-precision decimal numbers | float x = 3.2f; |
double |
Stores double-precision decimal numbers | double a = 9.97585858; |
char |
Stores a single character | char initial = 'A'; |
bool |
Stores logical values: true or false |
bool isStudent = true; |
string |
Stores a sequence of characters (text) | string name = "Aditya"; |
Note: In C++,
string
is part of the Standard Library and requires:#include <string> using std::string;
Conclusion Mastering data types is essential for writing reliable, efficient, and expressive programs. Each type—whether it's an integer for counting, a float for precision, or a string for text—serves a unique purpose in representing and manipulating information.
By understanding how and when to use these types, you lay the groundwork for structured logic, memory management, and robust application development in C++. 🧱💻