My Report

C# Operators Test – 3


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. Select the relevant C# code set to fill up the blank for the following C# program?

  static void Main(string[] args)
  {
      int x = 10, y = 20;
      int res;
      /*_______________*/ 
      Console.WriteLine(res);
  }

2. Arrange the operators in the increasing order as defined in C#.

    !=,   ?:,   &,   ++,  && 

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

 static void Main(string[] args)
 {
     byte varA = 10;
     byte varB = 20;
     long result = varA & varB;
     Console.WriteLine("{0}  AND  {1} Result :{2}", varA, varB, result);
     varA = 10;
     varB = 10;
     result = varA & varB;
     Console.WriteLine("{0}  AND  {1} Result : {2}", varA, varB, result);
     Console.ReadLine();
 }

4. Which of the following options is not a Bitwise Operator in C#?

5. 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();
 }

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

public static void Main(string[] args)
{
    int a = 4;
    int c = 2;
    bool b = (a % c == 0 ? true : false);
    Console.WriteLine(b.ToString());
    if (a/c == 2)
    {
        Console.WriteLine("true");
    }
    else
    {
        Console.WriteLine("false");
    }
    Console.ReadLine();
} 

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

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

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

 static void Main(string[] args)
 {
     int y = 5;
     int x;
     int k = (!(Convert.ToInt32(y) > 10))?  x = y + 3 : x = y + 10;
     Console.WriteLine(x);
     Console.WriteLine(y);
     Console.ReadLine();
 }

9. Which among the following is a conditional operator?

10. 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);
 }
 

 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

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.