bool a = true; bool b = false; bool c = true; if (a && b || c) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }
The expression a && b || c is evaluated as (a && b) || c. Since a && b is false and c is true, the overall expression is true. So, "Yes" is printed.
bool x = false; bool y = true; if (!(x || y) && y) { Console.WriteLine("True branch"); } else { Console.WriteLine("False branch"); }
The expression !(x || y) && y becomes !(false || true) && true which is !true && true → false && true → false. So the else branch runs.
bool isAdmin = true; bool isActive = false; if (isAdmin || isActive) { Console.WriteLine("Access granted"); } else { Console.WriteLine("Access denied"); }
The condition isAdmin || isActive allows access if either is true. The requirement is both must be true, so it should be isAdmin && isActive.
Option B is missing a closing parenthesis before the opening brace, causing a syntax error.
bool[] flags = { true, false, true, false, true };
int count = 0;
foreach (bool flag in flags)
{
if (flag && !(!flag || false))
{
Console.WriteLine("Condition met");
count++;
}
}
Console.WriteLine(count);The condition flag && !(!flag || false) simplifies to flag && flag which is just flag. So it prints once for each true in the array, which are 3 times.
