Recall & Review
beginner
What are relational operators in C++?
Relational operators compare two values and return true or false depending on the comparison result.
Click to reveal answer
beginner
List the six common relational operators in C++.
The six common relational operators are:<br>1. == (equal to)<br>2. != (not equal to)<br>3. < (less than)<br>4. > (greater than)<br>5. <= (less than or equal to)<br>6. >= (greater than or equal to)
Click to reveal answer
beginner
What is the output of this code?<br>
int a = 5, b = 10;<br>std::cout << (a < b);
The output is
1 because 5 is less than 10, so the expression a < b is true. In C++, true prints as 1.Click to reveal answer
beginner
How do relational operators help in decision making in C++?
Relational operators are used in conditions to decide which code to run. For example, in an
if statement, they check if a condition is true or false to choose the path.Click to reveal answer
beginner
What is the difference between == and = in C++?
== is a relational operator that checks if two values are equal.<br>= is an assignment operator that sets a value to a variable.<br>Using = instead of == in a condition causes errors or unexpected behavior.Click to reveal answer
Which operator checks if two values are NOT equal in C++?
✗ Incorrect
The operator != means 'not equal to' and returns true if values differ.
What does the expression (7 > 3) return in C++?
✗ Incorrect
7 is greater than 3, so (7 > 3) is true, which prints as 1.
Which relational operator means 'less than or equal to'?
✗ Incorrect
The operator <= means 'less than or equal to'.
What is the result of (5 == 5) in C++?
✗ Incorrect
5 equals 5, so (5 == 5) is true.
Which operator is used to assign a value to a variable?
✗ Incorrect
The = operator assigns a value to a variable, not to compare.
Explain what relational operators do in C++ and give examples.
Think about how you check if one number is bigger or smaller than another.
You got /3 concepts.
Describe how relational operators are used in decision making with if statements.
Imagine deciding what to do based on comparing two things.
You got /4 concepts.