C# Set 1( 20 mcqs)

1. Select the output for following set of code :
1. static void Main(string[] args)
2. {
3.     int i = 30;
4.     int j = 25 % 25;
5.     if (Convert.ToBoolean(Convert.ToInt32(i = j)))
6.     {
7.         Console.WriteLine(“In if”);
8.     }
9.     else
10.     {
11.         Console.WriteLine(“In else”);
12.     }
13.     Console.WriteLine(“In main”);
14.     Console.ReadLine();
15. }
a) In if
b) In else
c) In if
In main
d) In else
In main

2. Select output for following set of Code:
1. static void Main(string[] args)
2. {
3.     int i;
4.     int b = 8, a = 32;
5.     for (i = 0; i <= 10; i++)
6.     {
7.         if ((a / b * 2)== 2)
8.         {
9.             Console.WriteLine( i + ” “);
10.             continue;
11.         }
12.         else if (i != 4)
13.             Console.Write(i + ” “);
14.         else
15.             break;
16.    }
17.    Console.ReadLine();
18. }
a) 1 2 3 4 5 6 7 8 9
b) 0 1 2 3 4 5 6 7 8
c) 0 1 2 3
d) 0 1 2 3 4

3. Select the output for following set of Code:
1. static void Main(string[] args)
2. {
3.     Console.WriteLine(“Enter a letter:”);
4.     char c = (char)Console.Read();
5.     if (Char.IsDigit(c) == true)
6.         Console.WriteLine(“A number”);
7.     else if (char.IsLower(c) == true)
8.         Console.WriteLine(“A lower case letter”);
9.     else if (char.IsUpper(c) == true)
10.         Console.WriteLine(“An upper case letter”);
11.     Console.ReadLine();
12. }
13. 1. Enter a letter :
14.    a
15.    An upper case letter
16. 2. Enter a letter :
17.    A
18.    An upper case letter
19. 3. Enter a letter :
20.    2
21.    A number
22. 4. Enter a letter :
23.    2
24.    A lower case letter.
Which of following conditions are true ?
a) a ,b ,c
b) b ,c ,d
c) a ,d ,b
d) b ,c

4. Select the output for following set of code :
1.  static void Main(string[] args)
2.  {
3.      int i, j;
4.      for (i = 2; i >= 0; i–)
5.      {
6.          for (j = 0; j <= 2; j++)
7.          {
8.              if (i == j)
9.              {
10.                  Console.WriteLine(“1”);
11.              }
12.              else
13.              {
14.                  Console.WriteLine(“0”);
15.              }
16.         }
17.         Console.WriteLine(“\n”);
18.         Console.ReadLine();
19.      }
20.  }
a) 1 0 0
0 1 0
0 0 1
b) 0 1 0
1 0 0
0 0 1
c) 0 0 1
0 1 0
1 0 0
d) 1 0 0
0 0 1
0 1 0

5. Select the relevant ‘if statement’ to be placed in following set of code :
1. static void Main(string[] args)
2. {
3.     int []num = {50, 65, 56, 88, 43, 52};
4.     int even = 0, odd = 0;
5.     for (int i = 0 ;i < num.Length ;i++)
6.     {
7.          /*___________________________*/
8.     }
9.     Console.WriteLine(“Even Numbers:” +even);
10.     Console.WriteLine(“Odd Numbers:” +odd);
11.     Console.ReadLine();
12. }
a) if ((num % 2) == 0)
{
even += 1;
}
else
{
odd += 1;
}
b) if((num * i) == 0)
{
even += 1;
}
else
{
odd += 1;
}
c) if(num[i] % 2 == 0)
{
even += 1;
}
else
{
odd += 1;
}
d) if(num[i] % 2 = 0)
{
even += 1;
}
else
{
odd += 1;
}

6. What is the output for the following code ?
1. static void Main(string[] args)
2. {
3.     int a = 15, b = 10, c = 1;
4.     if (Convert.ToBoolean(a) && (b > c))
5.     {
6.         Console.WriteLine(“cquestionbank”);
7.     }
8.     else
9.     {
10.         break;
11.     }
12. }
a) cquestionbank
b) It will print nothing
c) Compile time error
d) Run time error

7. What is the output for the following code ?
1.  static void Main(string[] args)
2.  {
3.      int a = 5;
4.      if (Convert.ToBoolean((.002f) -(0.1f)))
5.      Console.WriteLine(“Sachin Tendulkar”);
6.      else if (a == 5)
7.      Console.WriteLine(“Rahul Dravid”);
8.      else
9.      Console.WriteLine(“Ms Dhoni”);
10.      Console.ReadLine();
11.  }
a) Rahul Dravid
b) Sachin Tendulkar
c) Ms Dhoni
d) Warning : Unreachable Code

8. Select the output for following set of Code :
1.  static void Main(string[] args)
2.  {
3.      int a = -1;
4.      int b = -1;
5.      if (Convert.ToBoolean (++a = ++b))
6.      Console.WriteLine(“a”);
7.      else
8.      Console.WriteLine(“b”);
9.      Console.ReadLine();
10.  }
a) a
b) b
c) Compile time error
d) Code execute successfully with no output

9. Select the output for following set of Code :
1.  static void Main(string[] args)
2.  {
3.      int a = 5, b = 10;
4.      if (Convert.ToBoolean(Convert.ToInt32(0xB)))
5.      if (Convert.ToBoolean(Convert.ToInt32(022)))
6.      if (Convert.ToBoolean(Convert.ToInt32(‘\xeb’)))
7.      Console.WriteLine(“java”);
8.      else ;
9.      else ;
10.      else ;
11.  }
a) Compile time error: Misplaced else
b) Compile time error: Undefined symbol
c) java
d) Warning: Condition is always true

10. Select the output for following set of Code :
1. static void Main(string[] args)
2. {
3.     int a = 5, b = 10;
4.     if (Convert.ToBoolean(Convert.ToInt32(++a)) || Convert.ToBoolean(Convert.ToInt32(++b)))
5.     {
6.         Console.WriteLine(a + “\n” + b);
7.     }
8.     else
9.     Console.WriteLine(” C# “);
10. }
a) 6 11
b) 6 16
c) 6 12
d) 6 10

11. Select output for following set of code :
1. static void Main(string[] args)
2. {
3.     int i = 1, j = 2, k = 3;
4.     do
5.     {
6.         Console.WriteLine((Convert.ToBoolean(Convert.ToInt32(i++))) && (Convert.ToBoolean(Convert.ToInt32(++j))));
7.     }while (i <= 3);
8.     Console.ReadLine();
9. }
a) 0 0 0
b) True True True
c) 1 1 1
d) False False False

12. Select output for following set of code :
1.static void Main(string[] args)
2.{
3.    float i = 1.0f, j = 0.05f;
4.    do
5.    {
6.        Console.WriteLine(i++ – ++j);
7.    }while (i < 2.0f && j <= 2.0f);
8.    Console.ReadLine();
9.}
a) 0.05
b) -0.05
c) 0.95
d) -0.04999995

13. Select the output for following code :
1.static void Main(string[] args)
2.{
3.    int i = 1, j = 5;
4.    do
5.    {
6.        Console.WriteLine(i = i++ * j);
7.    }while (i <= 10);
8.    Console.ReadLine();
9.}
a) 5 10 15 20 25 30 35 40 45 50
b) 5 25
c) 5 11 16 21 26 31 36 41 46 51
d) 5 30

14. Select the set of Code for following :
1. static void Main(string[] args)
2. {
3.     int i = 1234 ,j = 0;
4.      /*ADD CODE HERE */
5.     Console.WriteLine(j);
6. }
a) do
{
j = j + (i % 10);
}while ((i = i / 10)!= 0);
b) do
{
j = j + (i % 10);
}while ((i / 10)!= 0);
c) do
{
j = j + (i % 10);
}while ((i % 10)!= 0);
d) do
{
j = j + (i % 10);
}while ((i/10 == 0)!= 0);

15 Select the output for following set of code :
1. static void Main(string[] args)
2. {
3.     long  x;
4.     x = Convert.ToInt32(Console.ReadLine());
5.     do
6.     {
7.         Console.WriteLine(x % 10);
8.     }while ((x = x / 10) != 0);
9.     Console.ReadLine();
10. }
11. enter x = 1234.
a) number of digits present in x
b) prints ’1′
c) prints reverse of x
d) prints sum of digits of ‘x’

16. Select output for following set of code :
1. static void Main(string[] args)
2. {
3.     int i, s = 0, a = 1, d;
4.     i = Convert.ToInt32(Console.ReadLine());
5.     do
6.     {
7.         d = i % (2 * 4);
8.         s = s + d * a;
9.     }while ((Convert.ToInt32(i = i / (2 * 4))) != 0 && (Convert.ToBoolean(Convert.ToInt32((a) = (a * 10)))));
10.     Console.WriteLine(s);
11.     Console.ReadLine();
12. }
13.enter i = 342.
a) It finds binary equivalent of i
b) It finds octal equivalent of i
c) It finds sum of digits of i
d) It finds reverse of i

17. Correct syntax for do while loop is :
a) do;
{
statement;
}while (condition);
b) do(condition)
{
statement;
}while;
c) do
{
statement;
}while (condition)
d) do
{
statement;
}while (condition);

18. Select the output for following set of code :
1.static void Main(string[] args)
2.{
3.    int x = 10;
4.    do
5.    {
6.        Console.WriteLine( x++);
7.    }
8.    while(Convert.ToBoolean(5) && Convert.ToBoolean(4) && Convert.ToBoolean(3) && Convert.ToBoolean(2) && Convert.ToBoolean(1) && Convert.ToBoolean(0));
9.    Console.ReadLine();
10.}
a) 13
b) 15
c) 11
d) 10

19. Select output for following set of code :
1.static void Main(string[] args)
2.{
3.    int x;
4.    for (x = 10; x <= 15; x++)
5.    while (Convert.ToBoolean(Convert.ToInt32(x)))
6.    {
7.        do
8.        {
9.            Console.WriteLine(1);
10.            if (Convert.ToBoolean(x >> 1))
11.            continue;
12.        }while (Convert.ToBoolean(0));
13.        break;
14.    }
15.    Console.ReadLine();
16.}
a) 0 0 0….infinite times
b) 1 1 1….infinite times
c) 1 1 1 1 1 1
d) System outofflow exception error.

20. Select the output for following set of code :
1.static void Main(string[] args)
2.{
3.    int x = 0;
4.    do
5.    {
6.        x++;
7.        if (x == 5)
8.        {
9.            x++;
10.            continue;
11.            break;
12.        }
13.        Console.WriteLine(x + ” “);
14.    }
15.}while (x < 10);
a) 1 2 3 4 5
b) 10
c) 5 6 7 8 9 10
d) 1 2 3 4 5 6 7 8 9 10

Answers

1-d 2-c 3-d 4-c 5-c
6-c 7-b 8-c 9-c 10-d
11-b 12-d 13-b 14-a 15-c
16-b 17-d 18-d 19-c 20-d

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

shares