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

4/4

Page

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

What will be the output of the following C# code?
int n = 2;
int p = 4;
int q = 5;
int w = 3;
if ( !((p * q) /n <= (q * w) + n/p ))
{
    Console.WriteLine( ++p + w++ + " " + ++n);
    Console.WriteLine("b");
}
else
{
    Console.WriteLine(--p + q-- + " " + --n);
    Console.WriteLine("a");
}

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 b= 11;
    int c = 7;
    int r = 5;
    int e = 2;
    int l;
    int v = 109;
    int k;
    int z,t,p;
    z = b * c;
    t = b * b;
    p = b * r * 2;
    l = (b * c) + (r * e) + 10;
    k = v - 8;
    Console.WriteLine(Convert.ToString(Convert.ToChar(z)) + " " + Convert.ToString(Convert.ToChar(t)) + Convert.ToString(Convert.ToChar(p)) +   Convert.ToString(Convert.ToChar(l)) + Convert.ToString(Convert.ToChar(v)) + Convert.ToString(Convert.ToChar(k)));                
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
bool a = true;
bool b = false;
a |= b;
Console.WriteLine(a);
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 = 4, b = 5, c = 7, u = 9;
    int h;
    h = (Convert.ToInt32(u < b)) + (a + b--) + 2;
    Console.WriteLine(h);
    Console.WriteLine(b);
    Console.WriteLine(u < b);
}

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;
    int c = 10;
    int d = 12;
    int e = 5;
    int f = 6;
    a = c * (d + e) / f + d;
    Console.WriteLine(a);
    b = c * ( d + e / f + d);
    Console.WriteLine(b);
    if (a < b)
    {
        Console.WriteLine(" parentheses changes values");
    }
    else if (a > b)
    {
        Counterintelligence("they have same value");
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

Which of the following is/are not Relational operators in C#.NET?

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 = 80;
    b = 15;
    c = 2;
    x = a - b / (3 * c) * ( a + c);
    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)
{
    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();
}

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;
    z = 3 * x * x + 2 * x + 4 / x + 8;
    for (c = 1; c <= n; c++)
    {
        for (k = 1; k <= c; k++)
        {
            Console.Write(Convert.ToString(Convert.ToChar(z)));
            z++;
        }
        Console.WriteLine("\n");
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
int i, j = 1, k;
for (i = 0; i < 3; i++)
{
    k = j++ - ++j;
    Console.Write(k + " ");
}

Select an option to see the answer and solution.

The correct way of incrementing the operators are:

Select an option to see the answer and solution.

What will be the output of the following C# code?
class method1
{
    public int fun(int m)
    {
        return( m++ % 10);
    }
}
class Program
{
    static void Main(string[] args)
    {
        int a = 23, b = 0, c;
        method1 z = new method1();
        c = z.fun (++b * --a % 2);
        int d = (z.fun (c-- + --a));
        Console.WriteLine(c);
        Console.WriteLine(a++);
        Console.WriteLine(d);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.