What will be the output of the following C# code? [code] static void Main(string[] args) { int a = 5, b = 10; if (Convert.ToBoolean(

What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     int a = 5, b = 10;
     if (Convert.ToBoolean(Convert.ToInt32(++a)) || Convert.ToBoolean(Convert.ToInt32(++b)))
     {
         Console.WriteLine(a + "\n" + b);
     }
     else
     Console.WriteLine(" C# ");
 }
A. 6 11
B. 6 16
C. 6 12
D. 6 10
 
Answer: d
Explanation: Consider the following expression:( ++a || ++b). In this expression || is 'Logical OR operator'. Two important properties of this operator are:
Property 1:
(Expression1) || (Expression2)
|| operator returns 0 if and only if both expressions return a zero otherwise || operator returns 1.
initial value of a is 5. So ++a will be 6. Since ++a is returning a non-zero so ++b will not execute.
Output :
Code:
 6 10.
 

Tìm kiếm

Back
Top