Variables
C++ works very close to memory, so you must carefully label what you store with a type.
How to make C++ remember things
int number = 2026;
std::string welcome = "Hello, C++!";
Translation:
Remember one number (int) named number with the value 2026;
Remember one string named welcome with the value "Hello, C++!";
In C++, every sentence must end with a semicolon (;).
Basic types you can use in C++
int age = 20; // integer (most common)
double score = 95.5; // floating-point number
char grade = 'A'; // a single character
bool isReady = true; // true or false
std::string name = "Alex"; // a string of text
Pull it out yourself
#include <iostream>
#include <string>
int main() {
int x = 7;
std::cout << "The number I remembered is " << x << "!" << std::endl;
return 0;
}
C++ strictly enforces the types you declare. If you try to put text into a number box, it will immediately warn you. That strictness is what helps you build solid, bug-resistant programs.