What will be the output of the following C# code? [code] static void Main(string[] args) { int a = 4, b = 5, c = 7, u = 9;

Man Ly

New member
What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     int a = 4, b = 5, c = 7, u = 9;
     int h;
     h = (Convert.ToInt32(u < b)) + (a + b--) + 2;
     Console.WriteLine(h);
     Console.WriteLine(b);
     Console.WriteLine(u < b);
 }
A. 12, 5, 0
B. 11, 4, False
C. 11, 5, 0
D. 12, 4, False
 
Answer: b
Explanation: Step 1: Convert.ToInt32(u < b)(Evaluate result as 9 < 5 which is false in nature. So, solution is converted from 'false' to '0').
Code:
             Step 2: (a + b--) evaluated as 4 + 5 = 9 + 2 = 11.
             Step 3: u &lt; b evaluated as 'False' without being converted to '0'.
Output: 11
         4
         False.
 

Tìm kiếm

Back
Top