0
0
C++programming~10 mins

Variable declaration and initialization in C++ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an integer variable named age and initialize it with 25.

C++
int [1] = 25;
Drag options to blanks, or click blank then click option'
Aage
Bnumber
Cvalue
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not descriptive.
Forgetting to initialize the variable.
2fill in blank
medium

Complete the code to declare a floating-point variable named price and initialize it with 19.99.

C++
float [1] = 19.99f;
Drag options to blanks, or click blank then click option'
Avalue
Bprice
Camount
Dcost
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer type instead of float.
Forgetting the 'f' suffix for float literals.
3fill in blank
hard

Fix the error in the code by completing the variable declaration for a character named grade initialized with 'A'.

C++
char [1] = 'A';
Drag options to blanks, or click blank then click option'
Aletter
Bscore
Cmark
Dgrade
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes for char.
Using an incorrect variable name.
4fill in blank
hard

Fill both blanks to declare a boolean variable named isOpen and initialize it with true.

C++
bool [1] = [2];
Drag options to blanks, or click blank then click option'
AisOpen
Bfalse
Ctrue
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names.
Assigning a string instead of a boolean value.
5fill in blank
hard

Fill both blanks to declare a constant integer named MAX_USERS initialized with 100.

C++
const int [1] = [2];
Drag options to blanks, or click blank then click option'
AMAX_USERS
B100
DmaxUsers
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase variable names for constants.
Adding unnecessary suffixes to integer literals.