What will be the output of the following C# code? [code] static void Main(string[] args) { int i = 0; while (i++ != 0)

What will be the output of the following C# code?
Code:
  static void Main(string[] args)
  {
      int i = 0;
      while (i++ != 0) ;
      Console.WriteLine(i);
      Console.ReadLine();
  }
A. -127 to +127
B. 0 to 127
C. 1
D. Infinite loop condition
 
Answer: c
Explanation: i++ = first executes then increments as i = 0. So, i++ != 0, which is false clearly as i = 0. Now, control goes inside loop with i =
Code:
 1.
So, statement prints i =
Code:
 1.
Output:
Code:
 1.
 

Tìm kiếm

Back
Top