C# - Operators Question and Answer

C# - Operators Question and Answer
1. Which of the following are the correct ways to increment the value of variable a by 1?

    1.    ++a++;
    2.      a += 1;
    3.    a ++ 1;
    4.    a = a +1;
    5.    a = +1;
  • 1, 3
  • 2, 4
  • 3, 5
  • 4, 5
Show Answer
2. What will be the output of the C#.NET code snippet given below?

byte b1 = 0xF7;
byte b2 = 0xAB;
byte temp;
temp = (byte)(b1 & b2);
Console.Write (temp + " ");
temp = (byte)(b1^b2);
Console.WriteLine(temp);
  • 163 92
  • 92 163
  • 192 63
  • 0 1
Show Answer
3. Which of the following is NOT an Arithmetic operator in C#.NET?
  • **
  • +
  • /
  • %
Show Answer
4. Which of the following are NOT Relational operators in C#.NET?
>=
    !=
    Not
    <=
    <>=

  • 1, 3
  • 2, 4
  • 3, 5
  • 4, 5
Show Answer
5. Which of the following is NOT a Bitwise operator in C#.NET?
  • &
  • |
  • <<
  • ^
Show Answer
6. Which of the following statements is correct about the C#.NET code snippet given below?
int d;
d = Convert.Tolnt32( !(30 < 20) );
  • A value 0 will be assigned to d.
  • A value 1 will be assigned to d.
  • A value -1 will be assigned to d.
  • The code reports an error.
Show Answer
7. Which of the following is the correct output for the C#.NET code snippet given below?
Console.WriteLine(13 / 2 + " " + 13 % 2);
  • 6.5 1
  • 6.5 0
  • 6 0
  • 6 1
Show Answer
8. Which of the following statements are correct about the Bitwise & operator used in C#.NET?
The & operator can be used to Invert a bit.
    The & operator can be used to put ON a bit.
    The & operator can be used to put OFF a bit.
    The & operator can be used to check whether a bit is ON.
    The & operator can be used to check whether a bit is OFF.

  • 1, 2, 4
  • 2, 3, 5
  • 3, 4
  • 3, 4, 5
Show Answer
9. Which of the following are Logical operators in C#.NET?

    &&
    ||
    !
    Xor
    %

  • 1, 2, 3
  • 1, 3, 4
  • 2, 4, 5
  • 3, 4, 5
Show Answer
10. Suppose n is a variable of the type Byte and we wish, to check whether its fourth bit (from right) is ON or OFF. Which of the following statements will do this correctly?
  • if ((n&16) == 16) Console.WriteLine("Third bit is ON");
  • if ((n&8) == 8) Console.WriteLine("Third bit is ON");
  • if ((n ! 8) == 8) Console.WriteLine("Third bit is ON");
  • if ((n ^ 8) == 8) Console.WriteLine("Third bit is ON");
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test