Recall & Review
beginner
What is a constant in C++?
A constant is a value that cannot be changed after it is set. It is declared using the
const keyword.Click to reveal answer
beginner
What is a literal in C++?
A literal is a fixed value written directly in the code, like
42, 3.14, or 'a'.Click to reveal answer
beginner
How do you declare a constant integer with value 10 in C++?
You write: <code>const int number = 10;</code> This means <code>number</code> cannot be changed later.Click to reveal answer
intermediate
What is the difference between a constant and a literal?
A literal is a fixed value written in code. A constant is a named variable that holds a fixed value and cannot be changed.
Click to reveal answer
intermediate
Why use constants instead of literals directly in code?
Constants make code easier to read and maintain. If the value changes, you only update it in one place.
Click to reveal answer
Which keyword declares a constant in C++?
✗ Incorrect
The
const keyword is used to declare constants in C++.What is the type of the literal
3.14 in C++?✗ Incorrect
The literal
3.14 is a floating-point number, usually double by default.Which of these is a valid constant declaration?
✗ Incorrect
The correct syntax is
const int x = 5; or int const x = 5;. Option C and D are invalid.Can you change the value of a constant after it is set?
✗ Incorrect
Constants cannot be changed once assigned.
Which of these is a character literal in C++?
✗ Incorrect
Character literals are enclosed in single quotes, like
'a'.Explain what constants and literals are in C++ and how they differ.
Think about fixed values and named fixed values.
You got /3 concepts.
Describe why using constants is better than using literals directly in your code.
Imagine changing a value used many times.
You got /3 concepts.