Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

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

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);
}
a) 20, 10
b) 30, 10
c) 10, 20
d) 10, 10

Answer: b
Explanation: There are two kinds of Shift operations “Right Shift” and “Left Shift”. Right Shift operation is used for shifting the bit positions towards right side. Left Shift operation is used for shifting the bit positions towards left side. When Right Shift operations are done on a binary value the bits are shifted one position towards the right.
Output :
10 OR 20 Result :30.
10 OR 10 Result :10.

Join The Discussion