0
0
C++programming~5 mins

Variable declaration and initialization in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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++?
Anumber = 5;
Bint number = 5;
Cint number;
Dint = 5 number;
What is the value of an uninitialized local variable in C++?
ACompiler error
BZero
CAlways one
DUndefined (garbage value)
Which keyword is used to declare a variable in C++?
Aint, float, char (type names)
Blet
Cdeclare
Dvar
What does this line do? double price(19.99);
ADeclares and initializes price with 19.99
BDeclares a double variable named price without value
CAssigns 19.99 to an existing variable price
DSyntax error
Which of these is NOT a valid variable name in C++?
Atotal_sum
Bvalue3
C2ndValue
D_count
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.