Challenge - 5 Problems
Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed arithmetic and logical operators
What is the output of the following C# code snippet?
C Sharp (C#)
int a = 5; int b = 3; bool result = a > 2 && b < 5 || a == 5; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in C#.
✗ Incorrect
The expression evaluates as (a > 2 && b < 5) || a == 5. Both a > 2 and b < 5 are true, so the left side is true. The right side a == 5 is also true. True || True is True.
❓ Predict Output
intermediate2:00remaining
Result of combined increment operators
What is the value of variable x after executing this code?
C Sharp (C#)
int x = 3; int y = x++ + ++x; // What is the value of x now? Console.WriteLine(x);
Attempts:
2 left
💡 Hint
Remember how postfix and prefix increments work and their evaluation order.
✗ Incorrect
x starts at 3. x++ uses 3 then increments to 4. ++x increments to 5 then uses 5. So y = 3 + 5 = 8. After this, x is 5.
❓ Predict Output
advanced2:00remaining
Output of bitwise and logical operators combined
What is the output of this code snippet?
C Sharp (C#)
int a = 6; // binary 0110 int b = 3; // binary 0011 bool result = (a & b) > 0 && (a | b) < 10; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Bitwise & and | have lower precedence than comparison operators.
✗ Incorrect
a & b = 2 (binary 0010), which is > 0 (true). a | b = 7 (binary 0111), which is < 10 (true). True && True is True.
❓ Predict Output
advanced2:00remaining
Value of variable after complex expression with ternary and arithmetic
What is the value of z after running this code?
C Sharp (C#)
int x = 4; int y = 2; int z = x > y ? x++ * 2 : y++ * 3; Console.WriteLine(z);
Attempts:
2 left
💡 Hint
The ternary operator evaluates only one branch. Postfix increment happens after the value is used.
✗ Incorrect
x > y is true (4 > 2). So z = x++ * 2 = 4 * 2 = 8. After this, x becomes 5.
❓ Predict Output
expert2:00remaining
Output of expression with mixed assignment and logical operators
What is the output of this code?
C Sharp (C#)
bool a = false; bool b = true; bool c = a = b || a && !b; Console.WriteLine(c);
Attempts:
2 left
💡 Hint
Remember operator precedence: && before ||, and assignment is right to left.
✗ Incorrect
Evaluate a && !b first: false && false = false. Then b || false = true || false = true. Then a = true, so c = true.