0
0
C++programming~10 mins

Constants and literals 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 a constant integer named MAX with value 100.

C++
const int MAX = [1];
Drag options to blanks, or click blank then click option'
A100
B10.0
Cmax
D"100"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers, which makes them strings.
Using a variable name instead of a literal value.
2fill in blank
medium

Complete the code to declare a constant floating-point number PI with value 3.14.

C++
const double PI = [1];
Drag options to blanks, or click blank then click option'
A3.14
B3,14
C"3.14"
Dpi
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma instead of a dot for decimals.
Putting the number inside quotes, making it a string.
3fill in blank
hard

Fix the error in the code to declare a constant character named LETTER with value 'A'.

C++
const char LETTER = [1];
Drag options to blanks, or click blank then click option'
Aletter
B"A"
CA
D'A'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes which create string literals.
Using unquoted letters which cause errors.
4fill in blank
hard

Complete the code to declare a constant boolean named IS_READY with value true.

C++
const bool IS_READY = [1];
Drag options to blanks, or click blank then click option'
A"true"
Btrue
Cfalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized True which is invalid in C++.
Using quotes which make it a string.
5fill in blank
hard

Complete the code to declare a constant string named GREETING with value "Hello".

C++
const std::string GREETING = [1];
Drag options to blanks, or click blank then click option'
AHello
B'Hello'
C"Hello"
Dstd::string("Hello")
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which are for characters.
Using unquoted words which cause errors.