Relational operators compare two values and return either true (1) or false (0) based on the comparison.
Click to reveal answer
beginner
List the six relational operators in C.
The six relational operators are: < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to), == (equal to), != (not equal to).
Click to reveal answer
beginner
What is the result type of a relational operator in C?
The result is an integer: 1 if the relation is true, 0 if false.
Click to reveal answer
beginner
Explain the difference between == and = in C.
== is a relational operator that checks if two values are equal. = is an assignment operator that sets a value to a variable.
Click to reveal answer
beginner
What will the expression (5 > 3) return in C?
It returns 1 because 5 is greater than 3, so the condition is true.
Click to reveal answer
Which operator checks if two values are NOT equal in C?
A!=
B==
C<=
D=
✗ Incorrect
!= means not equal, so it returns true if values differ.
What does the expression (7 <= 7) evaluate to?
A7
B0
C1
DError
✗ Incorrect
7 is less than or equal to 7, so the expression is true and returns 1.
Which relational operator means 'greater than or equal to'?
A>=
B==
C<=
D!=
✗ Incorrect
>= means greater than or equal to.
What is the result type of a relational operator in C?
Afloat
Bint (1 or 0)
Cchar
Dvoid
✗ Incorrect
Relational operators return int: 1 for true, 0 for false.
Which operator is used to assign a value to a variable?
A<
B!=
C==
D=
✗ Incorrect
= assigns a value; == compares values.
Explain what relational operators do in C and list all six operators.
Think about how you compare numbers in real life, like checking if one number is bigger or equal to another.
You got /8 concepts.
Describe the difference between the assignment operator and the equality operator in C.
Remember: one is for giving a value, the other is for checking values.
You got /3 concepts.
Practice
(1/5)
1. Which of the following relational operators in C checks if two values are equal?
easy
A. !=
B. ==
C. =
D. >
Solution
Step 1: Understand the purpose of each operator
The operator == is used to compare two values for equality. The single = is an assignment operator, != checks inequality, and > checks if left is greater than right.
Step 2: Identify the equality operator
Since == compares two values for equality, it is the correct relational operator for this purpose.
Final Answer:
== -> Option B
Quick Check:
Equality check = == [OK]
Hint: Equality uses double equals ==, not single = [OK]
Common Mistakes:
Confusing = (assignment) with == (equality)
Using != instead of ==
Using > instead of ==
2. Which of the following is the correct syntax to check if variable a is not equal to variable b in C?
easy
A. a !== b
B. a <> b
C. a =! b
D. a != b
Solution
Step 1: Recall the correct not equal operator in C
In C, the operator for not equal is !=. Other options like <> or !== are not valid in C.
Step 2: Verify the syntax correctness
The expression a != b correctly compares if a is not equal to b.
Final Answer:
a != b -> Option D
Quick Check:
Not equal operator = != [OK]
Hint: Use != for not equal in C, not <> or !== [OK]
Common Mistakes:
Using <> which is invalid in C
Writing =! instead of !=
Using !== which is from other languages
3. What will be the output of the following C code?
int a = 5, b = 10;
if (a > b) {
printf("True\n");
} else {
printf("False\n");
}
medium
A. True
B. 5
C. False
D. 10
Solution
Step 1: Evaluate the relational expression a > b
Variable a is 5 and b is 10. Since 5 is not greater than 10, the expression a > b is false.
Step 2: Determine which branch executes
Because the condition is false, the else block runs, printing "False".
Final Answer:
False -> Option C
Quick Check:
5 > 10 = false [OK]
Hint: Compare values carefully; 5 > 10 is false [OK]
Common Mistakes:
Assuming 5 > 10 is true
Confusing else and if blocks
Ignoring relational operator meaning
4. Identify the error in the following C code snippet:
int x = 7, y = 3;
if (x =< y) {
printf("x is less or equal to y\n");
}
medium
A. Using =< instead of <=
B. Missing semicolon after if condition
C. Using assignment operator inside if
D. Incorrect printf syntax
Solution
Step 1: Check the relational operator syntax
The operator =< is invalid in C. The correct operator for less than or equal is <=.
Step 2: Confirm other syntax correctness
The semicolon after if condition is not needed, assignment operator is not used here, and printf syntax is correct.
Final Answer:
Using =< instead of <= -> Option A
Quick Check:
Less or equal operator is <=, not =< [OK]
Hint: Remember <= for less or equal, not =< [OK]
Common Mistakes:
Swapping <= to =<
Adding semicolon after if condition
Confusing assignment = with comparison ==
5. Given the code below, what will be the output?
int a = 4, b = 4, c = 5;
if (a == b && b < c) {
printf("Yes\n");
} else {
printf("No\n");
}
Choose the correct output considering relational operators combined with logical operators.
hard
A. Yes
B. No
C. 4
D. Syntax Error
Solution
Step 1: Evaluate the first condition a == b
Both a and b are 4, so a == b is true.
Step 2: Evaluate the second condition b < c
b is 4 and c is 5, so b < c is true.
Step 3: Combine conditions with logical AND
Both conditions are true, so the combined condition is true, executing the if block.
Final Answer:
Yes -> Option A
Quick Check:
(4 == 4) && (4 < 5) = true [OK]
Hint: Both conditions must be true for && to print Yes [OK]
Common Mistakes:
Ignoring logical AND meaning
Mixing up == and =
Assuming false when both conditions true
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.