My Report

C# Programming Practice Test 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C# code?

  static void Main(string[] args)
  {
      int i = 2, j = 4;
      switch (i + j * 2)
      {
      case 1 :
      case 2 :
          Console.WriteLine("1 and 2");
          break;
      case 3 to 10:
          Console.WriteLine("3 to 10");
          break;
      }
      Console.ReadLine();
  }

2. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     byte b1 = 0 * AB;
     byte b2 = 0 * 99;
     byte temp;
     temp = (byte) ~b2;
     Console.Write( temp + " ");
     temp = (byte) (b1 << b2);
     Console.Write(temp + " ");
     temp = (byte)(b2  >> 2);
     Console.WriteLine(temp);
     Console.ReadLine();
 }

3. What will be the output of the following C# code?

  bool a = true;
  bool b = false;
  a |= b;
  Console.WriteLine(a);
  Console.ReadLine();
  

4. What will be the output of the following C# code?

 
  static void Main(string[] args)
  {
      int i = 5;
      for (; Convert.ToBoolean(Convert.ToInt32(i)); Console.WriteLine(i--)) ;
      Console.ReadLine();
  }

5. What will be the output of the following C# code?

static void Main(string[] args)
{
    int x;
    for (x = 1; x <= 3; x++)
    {
        int j = 1;
        do
        {
            j++;
        }while (x % j == 2);
        Console.WriteLine(x + " " + j);
    }
    Console.ReadLine();
}

6. What will be the output of the following C# code?

 public static void Main() 
 {
     byte varA = 10;
     byte varB = 20;
     long result = varA | varB; 
     Console.WriteLine("{0}  OR  {1} Result :{2}", varA, varB, result);
     varA = 10;
     varB = 10;
     result = varA | varB;  
     Console.WriteLine("{0}  OR  {1} Result : {2}", varA, varB, result);
 }
 

7. What is the correct syntax for do while loop?

8. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     int i = 2, j = 3, k = 4;
     switch (i + j - k)
     {
     case 0: case 2: case 4:
         ++i;
         k += j;
         break;
     case 1: case 3: case 5 :
         --i;
         k -= j;
         break;
     default:
         i += j;
         break;
     }
     Console.WriteLine(i + "\n" + j + "\n" + k);
     Console.ReadLine();
 }
 

9. What will be the output of the following C# code?

  static void Main(string[] args)
  {
      int i = 0, j = 0;
      while (i < 2)
      {
          l1: i--;
          while (j < 2)
          {
              Console.WriteLine("hi\n");
              goto l1;
          }
      }
      Console.ReadLine();
  }
 

10. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     int a = 5, b = 10;
     if (Convert.ToBoolean(Convert.ToInt32(++a)) || Convert.ToBoolean(Convert.ToInt32(++b)))
     {
         Console.WriteLine(a + "\n" + b);
     }
     else
     Console.WriteLine(" C# ");
 }

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.