What will be the output of the following C# code? [code] static void Main(string[] args) { float i = 1.0f, j = 0.05f;

What will be the output of the following C# code?
Code:
  static void Main(string[] args)
  {
      float i = 1.0f,  j = 0.05f;
      while (i  < 2.0f  &#038;&#038;  j  <= 2.0f)
      {
          Console.WriteLine(i++ - ++j);
      }
      Console.ReadLine();
  }
A. 0.05f
B.
Code:
 1.
50f
C.
Code:
-0.04999995f
D.
Code:
 1.
50f
 
Answer: c
Explanation: for while(i =
Code:
 1.
0f and j = 0.05f). We, had '&&' condition which gives '1'. So, control enters while loop. Since, i = 1 and i++ = first execute then increment. So, first with 'i' value as
Code:
 1.
0f and ++j = first increment and then executes we had j =
Code:
 1.
05f and Since operation (i++ - ++j) gives us a negative sign number. So, we can stick our choice to option '
Code:
-0.04999995f
' clearly. Now, as i = 2.0f so loop breaks.
Output:
Code:
-0.04999995f
 

Tìm kiếm

Back
Top