Introduction
Variables help us store and remember information in a program. They let us use names to keep data that can change or be used later.
Variables help us store and remember information in a program. They let us use names to keep data that can change or be used later.
type variableName = value;
type is the kind of data (like int for numbers, char for letters).
variableName is the name you give to the storage spot.
age that holds the number 25.int age = 25;
grade that holds the letter 'A'.char grade = 'A';
temperature that holds a decimal number.float temperature = 36.5f;
This program shows how a variable score can store a number, then change it later. It prints the score before and after updating.
#include <iostream> int main() { int score = 0; // Start with zero score std::cout << "Initial score: " << score << "\n"; score = 10; // Update score std::cout << "Updated score: " << score << "\n"; return 0; }
Variables make programs flexible because you can change their values anytime.
Always give variables clear names so your code is easy to understand.
Variables store information that your program can use and change.
They help keep your data organized and easy to work with.
age in C++?int and proper order: int age;.int main() {
int x = 5;
x = x + 3;
std::cout << x;
return 0;
}x starts at 5, then adds 3, so x becomes 8.std::coutx, which is 8.int main() {
int number;
number = 10
std::cout << number;
return 0;
}number = 10 is missing a semicolon at the end.std::cout is used correctly, and return statement is present.std::cout usage is wrongapples and oranges into total.Pass the test and this pattern moves unknown