devnotes.

Variables and Basic Data Types

C++ keeps all of C's primitive types and adds a genuine boolean type and a proper string class.

int age = 25;
float price = 19.99f;
double pi = 3.14159265;
char grade = 'A';
bool isActive = true;      // real boolean type — didn't exist in older C
std::string name = "Rahim"; // full string class, not a raw char array

std::cout << sizeof(int) << "\n"; // still available, same meaning as in C

bool in C++ is a first-class type with only two values, true and false — unlike old C, where any non-zero int stood in for "true". std::string (from <string>) is a proper class with automatic memory management: it grows and shrinks as needed, supports + for concatenation, == for comparison, and dozens of member functions — none of which C's raw, fixed-size, manually-managed char[] strings offer.

Signed/unsigned and short/long modifiers work exactly as in C, and sizeof behaves identically. The core difference in this chapter isn't the types themselves, but that C++ layers safer, richer alternatives (bool, std::string, and — coming next — auto and constexpr) on top of the same underlying primitives.

C++ Variables and Basic Data Types | DevNotes