What will be the output of the following C# code? [code] static void Main(string[] args) { int i, j; for (i = 1, j = i;

Ngoc Hue

New member
What will be the output of the following C# code?
Code:
  static void Main(string[] args)
  {
      int i, j;
      for (i = 1, j = i; i <= 3 &#038;&#038; j >= 0; i++, j--)
      {
          if (i == j)
              continue;
          else
              Console.WriteLine(j);
      }
      Console.ReadLine();
  }
A. i = 0, j = 1;
B. i = 1,
Code:
j = 0
;
C.
Code:
j = 0
;
D. None of the mentioned
 
Answer: c
Explanation: Since for i = 1, j = 1 and 1 <= 3 also 1 >= 0 we had i == j. But after i++ and j--. The initial value of 'j' which is '0' as j-- preferred other than value of 'j' in i = j.
Output:
Code:
j = 0
 

Tìm kiếm

Back
Top