0
0
C++programming~5 mins

Relational operators in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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++?
A!=
B==
C<=
D>=
What does the expression (7 > 3) return in C++?
Afalse
B1
C0
DError
Which relational operator means 'less than or equal to'?
A>=
B==
C<=
D!=
What is the result of (5 == 5) in C++?
Afalse
B5
CError
Dtrue
Which operator is used to assign a value to a variable?
A=
B<
C!=
D==
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.