Recall & Review
beginner
What is a variable declaration in C++?
A variable declaration tells the computer to create a space in memory to store a value of a specific type, but it does not assign a value yet.
Click to reveal answer
beginner
What does variable initialization mean?
Variable initialization means giving a variable its first value at the time it is created.
Click to reveal answer
beginner
How do you declare and initialize an integer variable named
age with the value 25 in C++?You write:
int age = 25; This creates the variable age and sets its value to 25.Click to reveal answer
intermediate
What happens if you declare a variable without initializing it?
The variable has an undefined value (garbage) until you assign a value to it. Using it before assignment can cause errors.
Click to reveal answer
intermediate
Show two ways to initialize a variable in C++.
1. Using assignment:
int x = 10;<br>2. Using constructor style: int x(10);Click to reveal answer
Which of the following is a correct variable declaration and initialization in C++?
✗ Incorrect
Option B declares an integer variable named 'number' and initializes it with 5. Option C declares but does not initialize. Option A is an assignment without declaration. Option D is invalid syntax.
What is the value of an uninitialized local variable in C++?
✗ Incorrect
Local variables not initialized have undefined values, which means they contain whatever was in memory before.
Which keyword is used to declare a variable in C++?
✗ Incorrect
In C++, variables are declared by specifying their type like int, float, char, etc.
What does this line do?
double price(19.99);✗ Incorrect
This is constructor-style initialization of the variable price with the value 19.99.
Which of these is NOT a valid variable name in C++?
✗ Incorrect
Variable names cannot start with a number, so '2ndValue' is invalid.
Explain the difference between variable declaration and variable initialization in C++.
Think about creating a box versus putting something inside it.
You got /4 concepts.
Write an example of declaring and initializing a variable of type float with the value 3.14.
Use the syntax: type name = value;
You got /4 concepts.