## MCQs

Total Questions : 10
Question 1. Predict the output for the given set of code correctly.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();  }
1.    My Name
2.    My nAme
3.    My name
4.    Myname
Answer: Option C. -> My name

Solving the expression l = (b * c) + (r * e) + 10 .While from left to right the parentheses are given preference first.
Step 1 : b * c is evaluated first inside first parentheses.
Step 2 : r * e is evaluated second on right side of first addition symbol .
Step 3 : After evaluating both parentheses 10 is added to value of both.
Output : My name.

Question 2. Select the relevant code set to fill up the blank for the following program :
static void Main(string[] args)  {      int x = 10, y = 20;      int res;      /*_______________*/       Console.WriteLine(res);  }
1.    x % y == 0 ? (x == y ? (x += 2):(y = x + y)):y = y*10;
2.    x % y == 0 ? y += 10:(x += 10);
3.    x % y == 0 ? return(x) : return (y);
4.    All of the mentioned.
Answer: Option B. -> x % y == 0 ? y += 10:(x += 10);

{
int x = 10, y = 20;
int res;
x % y == 0 ? y += 10:(x += 10);
Console.WriteLine(res);
}

Question 3. Minimum and Maximum range of values supported by 'float' data type are ?
1.    1.5 * 10 ^-40 to 3.4 * 10 ^38
2.    1.5 * 10 ^-45 to 3.4 * 10 ^30
3.    1.5 * 10 ^-45 to 3.4 * 10 ^38
4.    1.5 * 10 ^-45 to 3.4 * 10 ^37
Answer: Option C. -> 1.5 * 10 ^-45 to 3.4 * 10 ^38

Question 4. Which is the String method used to compare two strings with each other ?
1.    Compare To()
2.    Compare()
3.    Copy()
4.    ConCat()

Compare() used to compare two strings by taking length of strings in considerations.

Question 5. Which datatype should be more preferred for storing a simple number like 35 to improve execution speed of a program?
1.    sbyte
2.    short
3.    int
4.    long

Wider datatype like int,long takes more time for manipulation of a program.

Question 6. What will be output of the following conversion ?
static void Main(string[] args) {     char a = 'A';     string b = "a";     Console.WriteLine(Convert.ToInt32(a));     Console.WriteLine(Convert.ToInt32(Convert.Tochar(b)));     Console.ReadLine(); }
1.    1, 97
2.    65, 97
3.    65, 97
4.    97, 1
Answer: Option C. -> 65, 97

ASCII value of character 'a' is 65 and ASCII value of string "a is 97. Output: 65,97

Question 7. Select output of the given set of Code :
static void Main(string[] args){    String name = "Dr.Gupta";    Console.WriteLine("Good Morning" + name);}
1.    Dr.Gupta
2.    Good Morning
3.    Good Morning Dr.Gupta
4.    Good Morning name
Answer: Option C. -> Good Morning Dr.Gupta

How to intialize a string variable and concatenate string using '+' operator. Output:Good Morning Dr.Gupta.

Question 8. Predict the output for the following set of 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);  }
1.    2 ,2 ,1
2.    2 ,3 ,2
3.    2 ,2 ,2
4.    2 ,0 ,9
Answer: Option C. -> 2 ,2 ,2

z = 6 as ++b.
y = 2 as ++c.
6 && 2 = 1
(++a == b ) which is false as 4!=6. Now, !(false) = true i.e 1.
So, 1 || 1 = 1. So, b = 1.
Similarly, c = 2 and a = 4.Now, 2 || 4 = 1.
So, a = 1.
Hence ++a = 2,++b = 2, c = 2.
Output : 2, 2, 2

Question 9. Scope of variable is related to definition of variable as:
1. Region of code within which variable value is valid and hence can be accessed.2. No, relation with region where variable is declared its value is valid in entire scope.
1.    a
2.    b
3.    a, b
4.    None of the mentioned

Scope of variable is the area or region within which variable is declared and hence intialized values of different kind. Based, on which operations of different kinds are carried out on that variable declared within that scope. Its value is preserved until and unless scope of that block ({ })is not expired because as soon as scope gets over. Hence, variable value gets expired. Hence, it's inaccessible after it.

Question 10. Type of Conversion in which compiler is unable to convert the datatype implicitly is ?
1.    ushort to long
2.    int to uint
3.    ushort to long
4.    byte to decimal
Answer: Option B. -> int to uint

'int' is 32 bit signed integer whereas 'uint' is 32 bit unsigned integer .Range of int is larger than uint.So,compiler cannot implicitly convert from larger datatype to smaller datatype.