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

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(0xB)))
      if (Convert.ToBoolean(Convert.ToInt32(022)))
      if (Convert.ToBoolean(Convert.ToInt32('\xeb')))
      Console.WriteLine("java");
      else ;
      else ;
      else ;
  }
A. Compile time error: Misplaced else
B. Compile time error: Undefined symbol
C. java
D. Warning: Condition is always true
 
Answer: c
Explanation:
Code:
                  oxB: hexadecimal integer constant.
                  022: It octal integer constant.
                 ‘\xeb’: It is hexadecimal character constant.
As zero is false and any non-zero number is true. All, constants return a non-zero value. So, all if conditions in the above program are true.
Output:
Code:
 java.
 

Tìm kiếm

Back
Top