Definition
📌 Data Types
C++ includes all of C's basic types (int, float, double, char) and adds a proper boolean type, bool, which can only be true or false..
Syntax
syntax
int wholeNumber;
double decimalNumber;
char singleCharacter;
bool trueOrFalse;Example
cpp
#include <iostream>
using namespace std;
int main() {
int age = 20;
double gpa = 8.9;
bool isEnrolled = true;
cout << age << " " << gpa << " " << isEnrolled << endl;
return 0;
}Output
output20 8.9 1
Important Points
boolstores onlytrueorfalse.doubleis generally preferred overfloatfor precision.autocombined with type suffixes (like5.0ffor float) controls exactly what type is inferred.- Use
std::string(from<string>) for real text, not justchar.
Common Mistakes
- Confusing C++'s
std::stringwith C's rawchararrays. - Forgetting that
boolprints as1/0unless you useboolalpha. - Losing precision by assigning a
doubleinto afloat.
Interview Tip
🎯 Before your interview
Know that
cout << boolalpha << true; prints "true" instead of "1" — a nice detail to mention in interviews.
