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 operator expressions
What is the output of the following C# code snippet?
C Sharp (C#)
int a = 5; int b = 3; int c = a++ * --b + b; Console.WriteLine(c);
Attempts:
2 left
💡 Hint
Remember the order of operations and how post-increment and pre-decrement work.
✗ Incorrect
The expression evaluates as follows:
a++uses 5, then incrementsato 6.--bdecrementsbfrom 3 to 2, then uses 2.- So,
5 * 2 + 2 = 10 + 2 = 12. - But the code prints
c, which is 12.
❓ Predict Output
intermediate2:00remaining
Result of logical operators
What is the output of this C# code?
C Sharp (C#)
bool x = true; bool y = false; bool result = x && y || !x && !y; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Recall operator precedence: && has higher precedence than ||.
✗ Incorrect
Evaluate step by step:
x && yistrue && false→false!x && !yisfalse && true→false- So
false || false→false
❓ Predict Output
advanced2:00remaining
Effect of operator overloading
Given the following class with operator overloading, what is the output of the code below?
C Sharp (C#)
public class Counter { public int Value { get; set; } public static Counter operator +(Counter c1, Counter c2) { return new Counter { Value = c1.Value + c2.Value + 1 }; } } Counter a = new Counter { Value = 2 }; Counter b = new Counter { Value = 3 }; Counter c = a + b; Console.WriteLine(c.Value);
Attempts:
2 left
💡 Hint
Check how the overloaded + operator adds an extra 1.
✗ Incorrect
The overloaded + operator adds the two values and then adds 1 extra.
So: 2 + 3 + 1 = 6.
❓ Predict Output
advanced2:00remaining
Difference between bitwise and logical operators
What is the output of this C# code snippet?
C Sharp (C#)
int x = 5; // binary 0101 int y = 3; // binary 0011 int result = x & y | x ^ y; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Recall bitwise AND (&), OR (|), and XOR (^) operations.
✗ Incorrect
Calculate step by step:
x & y= 0101 & 0011 = 0001 (decimal 1)x ^ y= 0101 ^ 0011 = 0110 (decimal 6)- Then
1 | 6= 0111 (decimal 7)
❓ Predict Output
expert2:00remaining
Operator precedence with mixed types
What is the output of this C# code?
C Sharp (C#)
int a = 4; double b = 2.5; var result = a / 2 + b * 3 - a % 2; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Remember operator precedence and type promotion in mixed expressions.
✗ Incorrect
Calculate step by step:
a / 2is integer division: 4 / 2 = 2b * 3is 2.5 * 3 = 7.5a % 2is 4 % 2 = 0- Expression: 2 + 7.5 - 0 = 9.5