What will be the output of the following C# code? [code] static void Main(string[] args) { int b= 11; int c = 7;

Việt Quân

New member
What will be the output of the following C# code?
Code:
  static void Main(string[] args)
  {
      int b= 11;
      int c = 7;
      int r = 5;
      int e = 2;
      int l;
      int v = 109;
      int k;
      int z,t,p;
      z = b * c;
      t = b * b;
      p = b * r * 2;
      l = (b * c) + (r * e) + 10;
      k = v - 8;
      Console.WriteLine(Convert.ToString(Convert.ToChar(z)) + " " + Convert.ToString(Convert.ToChar(t)) + Convert.ToString(Convert.ToChar(p)) +   Convert.ToString(Convert.ToChar(l)) + Convert.ToString(Convert.ToChar(v)) + Convert.ToString(Convert.ToChar(k)));                
      Console.ReadLine();
  }
A. My Name
B. My nAme
C. My name
D. Myname
 
Answer: c
Explanation: Solving the expression l = (b * c) + (r * e) + 10. While from left to right the parentheses are given preference first.
Code:
 Step 1 : b * c is evaluated first inside first parentheses.
 Step 2 : r * e is evaluated second on right side of first addition symbol.
 Step 3 : After evaluating both parentheses 10 is added to value of both.
Output : My name.
 

Tìm kiếm

Back
Top