What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 3, b = 5, c = 1;
int z = ++b;
int y = ++c;
b = Convert.ToInt32((Convert.ToBoolean(z)) && (Convert.ToBoolean(y))
|| Convert.ToBoolean(Convert.ToInt32(!(++a == b))));
a = Convert.ToInt32(Convert.ToBoolean(c) || Convert.ToBoolean(a--));
Console.WriteLine(++a);
Console.WriteLine(++b);
Console.WriteLine(c);
}
static void Main(string[] args)
{
int a = 3, b = 5, c = 1;
int z = ++b;
int y = ++c;
b = Convert.ToInt32((Convert.ToBoolean(z)) && (Convert.ToBoolean(y))
|| Convert.ToBoolean(Convert.ToInt32(!(++a == b))));
a = Convert.ToInt32(Convert.ToBoolean(c) || Convert.ToBoolean(a--));
Console.WriteLine(++a);
Console.WriteLine(++b);
Console.WriteLine(c);
}
A. 2, 2, 1
B. 2, 3, 2
C. 2, 2, 2
D. 2, 0, 9
Answer: Option C
Related Questions on Operators and Expressions in C Sharp
What does the modulus operator (%) do in C#?
A. Increments the operand by 1
B. Returns the quotient of a division
C. Performs multiplication
D. Returns the remainder of a division
Join The Discussion