Guided Notes

Variables, Data Types & Constants

Declaring variables, the fundamental types, std::string, auto, const and constexpr, type conversion, and formatting numbers.

Variables

Slide 1 / 5

A variable has a type, a name, and a value: int age = 36; double price = 9.99; char grade = 'A'; bool active = true; std::string city = "Austin";

C++ also offers brace initialization, which refuses narrowing conversions: int count{5}; int bad{3.7}; // compile error — would lose data

Always initialize variables: uninitialized locals hold garbage.

← Introduction to C++