Challenge - 5 Problems
Relational Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of relational operators with integers
What is the output of the following C code?
C
#include <stdio.h> int main() { int a = 5, b = 10; printf("%d\n", a < b); return 0; }
Attempts:
2 left
💡 Hint
Remember that relational operators return 1 for true and 0 for false in C.
✗ Incorrect
The expression 'a < b' is true because 5 is less than 10, so it returns 1.
❓ Predict Output
intermediate2:00remaining
Relational operator with equal values
What will be the output of this C program?
C
#include <stdio.h> int main() { int x = 7, y = 7; printf("%d\n", x >= y); return 0; }
Attempts:
2 left
💡 Hint
Check if x is greater than or equal to y.
✗ Incorrect
Since x equals y, 'x >= y' is true and returns 1.
❓ Predict Output
advanced2:00remaining
Output of chained relational expressions
What is the output of this C code snippet?
C
#include <stdio.h> int main() { int a = 3, b = 5, c = 7; printf("%d\n", a < b < c); return 0; }
Attempts:
2 left
💡 Hint
Remember how relational operators associate and the result of comparisons in C.
✗ Incorrect
The expression 'a < b < c' is evaluated left-to-right as '(a < b) < c'. 'a < b' is true (1), then '1 < c' (1 < 7) is true (1), so it prints 1.
❓ Predict Output
advanced2:00remaining
Relational operator with pointers
What will be the output of this C program?
C
#include <stdio.h> int main() { int arr[3] = {1, 2, 3}; int *p1 = &arr[0]; int *p2 = &arr[2]; printf("%d\n", p1 > p2); return 0; }
Attempts:
2 left
💡 Hint
Compare the memory addresses pointed by p1 and p2.
✗ Incorrect
Pointer p1 points to arr[0], which is at a lower address than p2 (arr[2]). So 'p1 > p2' is false (0).
🧠 Conceptual
expert3:00remaining
Behavior of relational operators with floating-point NaN
In C, what is the result of the expression (x < y) if x or y is NaN (Not a Number)?
Attempts:
2 left
💡 Hint
Think about how comparisons with NaN behave according to IEEE floating-point rules.
✗ Incorrect
Any comparison involving NaN returns false except '!=' which returns true. So 'x < y' is false (0) if either is NaN.