C# Set (30 mcqs)

1. How much Bytes are stored by ‘Long’ Datatype in C# .net?
a) 8
b) 4
c) 2
d) 1

2. Choose “.NET class” name from which datatype “UInt” is derived of?
a) System.Int16
b) System.UInt32
c) System.UInt64
d) System.UInt16

a) System.Int16 = short.
b) System.UInt32 = UInt.
c) System.UInt64 = ULong.
d) System.UInt16 = UShort.

3. Correct Declaration of Values to variables ‘a’ and ‘b’?
a) int a = 32, b = 40.6;
b) int a = 42; b = 40;
c) int a = 32; int b = 40;
d) int a = b = 42;
b) Missing deceleration type of ‘b’.
c) correctly declared datatypes ‘a’ and ‘b’.
d) ‘b’ can’t be assigned values before declaration.

4. Select error in a given program :
1.     Static Void Main(String[] args)
2.     {
3.   const int m = 100;
4.   int n = 10;
5.   const int k = n / 5 * 100 * n ;
6.   Console.WriteLine(m * k);
7.   Console.ReadLine();
8.     }
a) ‘k’ should not be declared constant
b) Expression assigned to ‘k’ should be constant in nature
c) Expression (m * k) is invalid
d) ‘m ‘ is declared in invalid format

5. Arrange following datatype in order of increasing magnitude sbyte, short, long, int.
a) long < short < int < sbyte
b) sbyte < short < int < long
c) short < sbyte < int < long
d) short < int < sbyte < long

6. Which datatype should be more preferred for storing a simple number like 35 to improve execution speed of a program?
a) sbyte
b) short
c) int
d) long

7. Which Conversion function of ‘Convert.TOInt32()’ and ‘Int32.Parse()’ is efficient?
1) Int32.Parse() only used for strings and throws arguement exception for null string
2) Convert.Int32() used for datatypes and returns directly ’0′ for null string
a) 2
b) Both 1,2
c) 1
d) None of the mentioned

8. Correct way to assign values to variable ‘c’ when int a=12, float b=3.5,int c;
a) c = a + b;
b) c = a + int(float(b));
c) c = a + convert.ToInt32(b);
d) c = int(a + b);

9. Correct Set of Code for given data ‘a’ and ‘b’ to print output for ‘c’ as 74 ?
a)
1. int a = 12;
2. float b = 6.2f;
3. int c;
4. c = a / b + a * b;
5. Console.WriteLine(c);
b)
1. int a = 12;
2. float b = 6.2f;
3. int c;
4. c = a / convert.ToInt32(b) + a * b;
5. Console.WriteLine(c);
c)
1. int a = 12;
2. float b = 6.2f;
3. int c;
4. c = a / convert.ToInt32(b) + a * convert.ToInt32(b);
5. Console.WriteLine(c);
d)
1.  int a = 12;
2.  float b = 6.2f;
3.  int c;
4.  c = convert.ToInt32(a / b + a * b);
5.  Console.WriteLine(c);

10. Is output remain same or different for both cases?
1)
1.char l =’k’;
2.float b = 19.0f;
3.int c;
4.c = (l / convert.ToInt32(b));
5.Console.Writeline(c);
2)
1. char l =’k’;
2. float b = 19.0f;
3. int c;
4. c = Convert.ToInt32(l / b);
5. console.writeline(c);
a)    Yes
b) No

11. Select a convenient deceleration and initializing of a floating point number:
a) float somevariable = 12.502D
b) float somevariable = (Double) 12.502D
c) float somevariable = (float) 12.502D
d) float somevariable = (Decimal)12.502D

12. Number of digits upto which precision value of float datatype is valid ?
a) Upto 6 digit
b) Upto 8 digit
c) Upto 9 digit
d) Upto 7 digit

13. Valid Size of float datatype is ?
a) 10 Bytes
b) 6 Bytes
c) 4 Bytes
d) 8 Bytes

14. Correct way to define a value 6.28 in a variable ‘a’ where value cannot be modified ?
a) #define a 6.28F
b) pi = 6.28F
c) const float pi = 6.28F
d) const float pi pi = 6.28F

15. Select correct set of code to display value of given variable ‘c’ as ’25.302′.
1.    a) float a = (double) 12.502f;
2. float b = 12.80f;
3. float c;
4. c = (float) a + b;
5. Console.Writeline(c);
6. Console.ReadLine();
7.    b) float a = 12.502D;
8. float b = 12.80f;
9. float c;
10. c = a + b;
11. Console.WriteLine(c);
12. Console.ReadLine();
13.    c) double a = 12.502;
14. float b = 12.802f;
15. float c;
16. c = (float)a + b;
17. Console.WriteLine(c);
18. Console.ReadLine();
19.    d) double a = (float) 12.502f;
20. float  b = 12.80f;
21. float  c;
22. c = a + b;
23. Console.WriteLine(c);
24. Console.ReadLine();

16. Minimum and Maximum range of values supported by ‘float’ data type are ?
a) 1.5 * 10 ^-40 to 3.4 * 10 ^38
b) 1.5 * 10 ^-45 to 3.4 * 10 ^30
c) 1.5 * 10 ^-45 to 3.4 * 10 ^38
d) 1.5 * 10 ^-45 to 3.4 * 10 ^37

17. Select appropriate difference between decimal, float and double data type in C# ?
1) Float and Double are floating binary point types while decimal is a floating decimal point type.
2) Precision difference for float is ’7′ digit for double is ’15′ to ’16′ digit and for decimal is ’28′ to ’29′ digits.
3) Some values which cannot be exactly represented hence for those values float and double are more appropriate.
a) 1
b) 1, 3
c) 1, 2, 3
d) 2, 3

18. Why does a float variable stop increments at number ’16777216′ in given code in C#?
1.     float a = 0 ;
2.     while (true)
3.     {
4.   a++;
5.   if (a > 16777216)
6.   break;
7.     }
a) Sign and Exponent for ’16777217′ is same as for ’16777216′
b) Mantisaa is different for ’16777216′ and ’16777217′
c) Sign and Exponent for ’16777217′ is different as for ’16777216′
d) None of the mentioned

19. Select output of following set of code ?
1.    static void Main(string[] args)
2.    {
3.  int x = 1;
4.  float y = 2. 4f;
5.  short z = 1;
6.  Console. WriteLine((float) x + y * z – (x + = (short) y) );
7.  Console. ReadLine();
8.    }
a) 0.4000004
b) 0.4000023
c) 0.0400021
d) 0.4000001

20. A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored ?
a) ABCD
b) DCBA
c) 0 * ABCD
d) Depends on big endian or little endian architecture

21. The Default value of Boolean DataType is ?
a) 0
b) True
c) False
d) 1
e) -1

21. Select the output for following set of code.
1.static void Main(string[] args)
2.{
3.    int movie = 1;
4.    switch (movie << 2 + movie)
5.    {
6.    default:
7.        Console.WriteLine(“3 Idiots”);
8.        break;
9.    case 4:
10.        Console.WriteLine(“Ghazini”);
11.        break;
12.    case 5:
13.        Console.WriteLine(“Krishh”);
14.        break;
15.    case 8:
16.        Console.WriteLine(“Race”);
17.        break;
18.    }
19.    Console.ReadLine();
20.}
a) 3 Idiots
b) Ghazini
c) Race
d) Krishh

22. Select the output for following set of code :
1.static void Main(string[] args)
2.{
3.    int i = 2, j = 4;
4.    switch (i + j * 2)
5.    {
6.    case 1 :
7.    case 2 :
8.        Console.WriteLine(“1 and 2”);
9.        break;
10.    case 3 to 10:
11.        Console.WriteLine(“3 to 10”);
12.        break;
13.    }
14.    Console.ReadLine();
15.}
a) 3 to 10 will be printed
b) 1 and 2 will be printed
c) The code reports an error as missing ; before :
d) The code gives output as 3 to 10

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

24. Select output for following set of code :
1. static void Main(string[] args)
2. {
3.     int const p = 0;
4.     switch (3 * 5 / 6)
5.     {
6.     case p:
7.         Console.WriteLine(“A”);
8.         break;
9.     case p * 1:
10.         Console.WriteLine(“B”);
11.         break;
12.     case p – 2:
13.         Console.WriteLine(“C”);
14.         break;
15.     default:
16.         Console.WriteLine(“D”);
17.     }
18.}
a) A
b) B
c) C
d) Compile time error

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

26. Select the output for following set of code :
1.static void Main(string[] args)
2.{
3.    int  i = 9 , j = 7;
4.    switch (i – j + 3)
5.    {
6.    case 9: 7:
7.        j += 6;
8.        break;
9.    case 5:
10.        i -= 4;
11.        break;
12.    }
13.    Console.WriteLine(i + “\n” + j);
14.    Console.ReadLine();
15.}
a) 5 7
b) 9 13
c) Compile time error
d) 9 7

27. Select the output for code :
1.static void Main(string[] args)
2.{
3.    switch (5)
4.    {
5.    case 5.0f:
6.        Console.WriteLine(“harsh”);
7.        break;
8.    case 5:
9.        Console.WriteLine(“amish”);
10.        break;
11.    case 5.0L:
12.        Console.WriteLine(“ANKIT”);
13.        break;
14.    default:
15.        Console.WriteLine(“ashish”);
16.    }
17.    Console.ReadLine();
18. }
a) amish
b) ANKIT
c) harsh
d) Compile time error

28. Select output for code:
1.static void Main(string[] args)
2.{
3.    int i;
4.    int j = 1;
5.    int []ar = {21, 22, 13, 4};
6.    switch (ar[j])
7.    {
8.    case 1:
9.        i++;
10.        break;
11.    case 2:
12.        i += 2;
13.        j = 3;
14.        continue;
15.    case 3:
16.       i %= 2;
17.       j = 4;
18.       continue;
19.    default:
20.       –i;
21.    }
22.    Console.WriteLine(i);
23.    Console.ReadLine();
24.}
a) 23
b) 15
c) Compile time error
d) 12

29. Select the output for following set of Code:
1.     static void Main(string[] args)
2.     {
3.   char ch = Convert.ToChar(‘a’ | ‘b’ | ‘c’);
4.   switch (ch)
5.   {
6.   case ‘A’:
7.   case ‘a’:
8.       Console.WriteLine(“case A|case a”);
9.       break;
10.   case ‘B’:
11.   case ‘b’:
12.       Console.WriteLine(“case B|case b”);
13.       break;
14.   case ‘C’:
15.   case ‘c’:
16.   case ‘D’:
17.   case ‘d’:
18.       Console.WriteLine(“case D|case d”);
19.       break;
20.   }
21.   Console.ReadLine();
22.     }
a) Compile time error
b) case A|case a
c) case B|case b
d) case D|case d

30. Select the output for following set of Code:
1.static void Main(string[] args)
2.{
3.    char ch = ‘p’;
4.    switch (ch)
5.    {
6.    case ‘p’:
7.        Console.WriteLine(“coco” + “\t” + Convert.ToInt32(ch));
8.        break;
9.    default:
10.        Console.WriteLine(“default”);
11.        break;
12.   }
13.   Console.WriteLine(“main”);
14.}
a) coco main
b) coco 112
c) coco 112 main
d) compile time error

Answers

1-a 2-b 3-c 4-b 5-b
6-a 7-a 8-c 9-c 10-b
11-c 12-d 13-c 14-c 15-c
16-c 17-b 18-d 19-d 20-c
21-c 22-c 23-c 24-d 25-a
26-c 27-d 28-c 29-d 30-c
Spread the love

Leave a Comment

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