0
0
C Sharp (C#)programming~20 mins

Operator precedence and evaluation order in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
AFalse
BTrue
CCompilation error
DRuntime exception
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in C#.
Predict Output
intermediate
2: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);
A5
B6
C3
D4
Attempts:
2 left
💡 Hint
Remember how postfix and prefix increments work and their evaluation order.
Predict Output
advanced
2: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);
ARuntime exception
BFalse
CCompilation error
DTrue
Attempts:
2 left
💡 Hint
Bitwise & and | have lower precedence than comparison operators.
Predict Output
advanced
2: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);
A8
B9
C6
D10
Attempts:
2 left
💡 Hint
The ternary operator evaluates only one branch. Postfix increment happens after the value is used.
Predict Output
expert
2: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);
ACompilation error
BFalse
CTrue
DRuntime exception
Attempts:
2 left
💡 Hint
Remember operator precedence: && before ||, and assignment is right to left.