Challenge - 5 Problems
Boolean Mastery in C#
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Boolean evaluation of integer values
What is the output of this C# code snippet?
C Sharp (C#)
int x = 0; if (x == 0) { Console.WriteLine(true); } else { Console.WriteLine(false); }
Attempts:
2 left
💡 Hint
Remember that in C#, integers are not implicitly converted to booleans.
✗ Incorrect
The condition 'x == 0' evaluates to true because x is zero. The code prints 'True'.
❓ Predict Output
intermediate2:00remaining
Boolean logic with && and || operators
What is the output of this C# code?
C Sharp (C#)
bool a = true; bool b = false; if (a && b || !b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }
Attempts:
2 left
💡 Hint
Evaluate the expression step by step using operator precedence.
✗ Incorrect
The expression evaluates as (true && false) || !false → false || true → true, so it prints 'Yes'.
❓ Predict Output
advanced2:00remaining
Boolean conversion and conditional operator
What is the output of this C# code?
C Sharp (C#)
int x = 5; string result = x > 3 ? "Greater" : "Smaller"; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Check the condition x > 3 and what the conditional operator returns.
✗ Incorrect
Since 5 is greater than 3, the condition is true, so 'Greater' is assigned and printed.
❓ Predict Output
advanced2:00remaining
Boolean negation and equality check
What is the output of this C# code?
C Sharp (C#)
bool flag = false; flag = !flag; Console.WriteLine(flag == true);
Attempts:
2 left
💡 Hint
Negate the initial value and then compare with true.
✗ Incorrect
flag starts as false, negation makes it true, so flag == true is true and prints 'True'.
🧠 Conceptual
expert2:00remaining
Boolean type strictness in C#
Which statement about Boolean type behavior in C# is correct?
Attempts:
2 left
💡 Hint
Think about how C# treats types strictly compared to some other languages.
✗ Incorrect
C# requires boolean expressions to be explicitly true or false; integers cannot be used as booleans without conversion.