Vidyalelo
C# Programming · all questions

Operators and Expressions in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

72

Questions

3/4

Page

Pick an option on a question to see the right answer and solution.

What is the result of the expression 9 % 4 in C#?

Select an option to see the answer and solution.

Which operator is used to perform inequality comparison in C#?

Select an option to see the answer and solution.

Correct order of priorities are:

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int a = 4;
    int b = 5;
    int c = 6;
    int d = 8;
    if (((a * b / c) + d) >= ((b * c + d ) / a))
    {
        Console.WriteLine("Line 1 - a is greater to b");
        Console.WriteLine((a * b / c) + d);
    }
    else
    {
        Console.WriteLine("Line 1 - a is not greater to b");
        Console.WriteLine((b * c + d )/ a);
    }
}

Select an option to see the answer and solution.

Which among the following is a conditional operator?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C# code?
m = 5;
int y;
1. y = m++;
2. y = ++m;

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int m = 10, n = 5, p = 20;
    bool b1 =  m * p / n <= p * n / m ;
    int l = p - 2 * m;
    bool b2 = l == 0;
    int z = Convert.ToInt32(b2);
    int k = Convert.ToInt32(b1);
    Console.WriteLine(k);
    Console.WriteLine(z);
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Arrange the operators in the increasing order as defined in C#.
!=,   ?:,   &,   ++,  &&

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
     int a, b, c, x;
     a = 90;
     b = 15;
     c = 3;
     x = a - b / 3 + c * 2 - 1;
     Console.WriteLine(x);
     Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    float a = 16.4f;
    int b = 12;
    float c;
    c =  a * ( b + a) / (a - b) ;
    Console.WriteLine("result is :" +c);
    Console.ReadLine();
}

Select an option to see the answer and solution.

Check the following C# code whether the given relation operator works according to the if condition or not.
static void Main(string[] args)
{
    int a = 10;
    int b = 5;
    int c = 12; 
    int e = 8;
    int d;
    d = Convert.ToInt32((a * (c - b) / e + (b + c)) <= (e * (c + a) / (b + c) + a));
    Console.WriteLine(d);
    if (d == 1)
    {
        Console.WriteLine("C# is great language!");
        Console.WriteLine((a * (c - b) / e + (b + c)));
    }
    else
    {
        Console.WriteLine("harsh is not great language!");
        Console.WriteLine((e * (c + a) / (b + c) + a));
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int a = 3, b = 5, c = 1;
    int z = ++b;
    int y = ++c;
    b = Convert.ToInt32((Convert.ToBoolean(z)) && (Convert.ToBoolean(y)) 
     || Convert.ToBoolean(Convert.ToInt32(!(++a == b))));
    a = Convert.ToInt32(Convert.ToBoolean(c) || Convert.ToBoolean(a--));
    Console.WriteLine(++a);
    Console.WriteLine(++b);
    Console.WriteLine(c);
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int a = 8, b = 6, c = 10;
    int d = a * c * 2 / Convert.ToInt32(Math.Pow ((c - b), 2));
    if (d == (c = Convert.ToInt32(Math.Sqrt (a * a + b * b))) && c == 10)
    {
        Console.WriteLine("figure is hypotenuse");
    }
    else
    {
       Console.WriteLine("figure is square");
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int n = 5;
    int x = 4;
    int z, c, k;
    for (c = 1; c <= n; c++)
    {
        for (k = 1; k <= c; k++)
    {
        z = 3 * x * x + 2 * x + 4 / x + 8;
        Console.Write(Convert.ToString(Convert.ToChar(z)));
    }
        Console.WriteLine("\n");
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.