Variables and Types
C++'s fundamental types include int, double, bool, and char. Every variable has a type, and that type is fixed once declared. Note that cout prints a bool as 0 or 1, not the words true/false, unless you explicitly ask for the word form.
#include <iostream>
using namespace std;
int main() {
int age = 30;
double price = 19.99;
bool isStudent = false;
char grade = 'A';
cout << age << " " << price << " " << isStudent << " " << grade << endl;
return 0;
}30 19.99 0 A
auto and const
auto lets the compiler infer a variable's type from its initializer — useful when the type is obvious or verbose, though it still produces a fixed, fully static type, not a dynamic one. const marks a variable as unmodifiable after initialization; the compiler enforces this at compile time.
#include <iostream>
using namespace std;
int main() {
auto count = 42; // inferred as int
auto pi = 3.14159; // inferred as double
const int maxUsers = 100;
cout << count << " " << pi << " " << maxUsers << endl;
return 0;
}42 3.14159 100
Next: references and pointers — two different ways to refer to a value without copying it, and the genuinely C++-specific distinction between them.
Practice exercise
Declare a variable temperature: double = 72.5 and a variable isSunny: bool = true. Print them together separated by a space.