Challenge - 5 Problems
Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of chained comparison operators
What is the output of this C# code snippet?
C Sharp (C#)
int a = 5; int b = 10; int c = 15; Console.WriteLine(a < b && b < c);
Attempts:
2 left
💡 Hint
Think about how logical AND works with comparison operators.
✗ Incorrect
The expression checks if a is less than b AND b is less than c. Both are true, so the output is True.
❓ Predict Output
intermediate2:00remaining
Result of equality and assignment operators
What will be printed by this code?
C Sharp (C#)
int x = 7; int y = 7; Console.WriteLine(x == y);
Attempts:
2 left
💡 Hint
Check if x and y have the same value.
✗ Incorrect
The '==' operator compares values. Since x and y are both 7, the result is True.
❓ Predict Output
advanced2:00remaining
Output of mixed comparison and logical operators
What is the output of this code?
C Sharp (C#)
int a = 3; int b = 4; int c = 5; Console.WriteLine(a < b || b > c && c == 5);
Attempts:
2 left
💡 Hint
Remember operator precedence: && before ||.
✗ Incorrect
The expression evaluates as (a < b) || ((b > c) && (c == 5)). a < b is true, so the whole expression is true.
❓ Predict Output
advanced2:00remaining
Value of variable after comparison and assignment
What is the value of variable result after running this code?
C Sharp (C#)
int x = 10; int y = 20; bool result = x > y; result = !result; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Check the initial comparison and then the negation.
✗ Incorrect
x > y is false, negating it with ! makes result true.
❓ Predict Output
expert2:00remaining
Output of complex comparison with nullable types
What will this code print?
C Sharp (C#)
int? a = null; int? b = 5; Console.WriteLine(a < b);
Attempts:
2 left
💡 Hint
Consider how nullable comparisons behave in C#.
✗ Incorrect
When comparing nullable ints, if one is null, the result is false for < operator.