C++ requires you to declare a variable with its type before using it:
int age = 30;
float price = 19.99;
char grade = 'A';
bool isActive = true;Use string for text (requires #include <string>).
You can declare multiple variables of the same type in a single line:
int x = 5, y = 10, z = 0;Always initialize variables to avoid undefined values:
int number; // might contain garbage
number = 42; // assigned later
int count = 0; // preferredVariables are accessible only within the block they are defined in:
void example() {
int local = 10;
cout << local;
}
// local is not accessible hereGlobal variables are declared outside any function.
Use const to declare constants:
const double PI = 3.14159;Constants cannot be reassigned after initialization.
studentAge)Ask the AI if you need help understanding or want to dive deeper in any topic