Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. What will be the output of the given code snippet?class access{    public int x;    private int y;    public  void cal(int a, int b)    {        x = a + 1;        y = b;    }    public  void print()    {       Console.WriteLine(" " + y);        } }    class Program{    static void Main(string[] args)    {        access obj = new access();           obj.cal(2, 3);        Console.WriteLine(obj.x);        obj.print();        Console.ReadLine();    }}
  1.    2 3
  2.    3 3
  3.    Run time error
  4.    Compile time error
 Discuss Question
Answer: Option B. -> 3 3




Question 2. What will be the declaration of the variable ptr as the pointer to array of 6 floats?
  1.    float *ptr[6].
  2.    float [6]*ptr
  3.    float(*ptr)[6].
  4.    float(*ptr)(6).
 Discuss Question
Answer: Option C. -> float(*ptr)[6].




Question 3. Which of these constructors is used to create an empty String object?
  1.    String()
  2.    String(void)
  3.    String(0)
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> String()




Question 4. Choose the statement which defines the Nullable type Correctly:
  1.    a special version of a value type that is represented by a structure
  2.    a nullable type can also store the value null
  3.    Nullable types are objects of System.Nullable, where T must be a non nullable value type
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


A nullable type is a special version of the value type that is represented by a structure. In addition to the values defined by the underlying type, a nullable type can also store the value null. Thus, a nullable type has the same range and characteristics as its underlying type. It simply adds the ability to represent a value which indicates that a variable of that type is unassigned. Nullable types are objects of System.
Nullable, where T must be a non- nullable value type.


Question 5. What does the given code set specifies?public static int Compare(string strA, string strB)
  1.    Comparison is case and culture sensitive
  2.    Two strings A and B are compared with each other
  3.    Output is : >0 for (A > B),
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


Compares the string referred to by strA with strB. Returns greater than zero if strA is greater than strB, less than zero if strA is less
than strB, and zero if strA and strB are equal. The comparison is case and culture-sensitive


Question 6. What will be the output of the code snippet?class Program {     static void Main(string[] args)     {         String s1 = "Hello World";         String s2 = s1.Substring(0, 4);         Console.WriteLine(s2);         Console.ReadLine();     } }
  1.    Hello
  2.    Hell
  3.    H
  4.    Hello World
 Discuss Question
Answer: Option B. -> Hell




Question 7. Select the output for given set of code:
static void Main(string[] args){    string s1 = "Hello" + "c" + "Sharp";    Console.WriteLine(s1);    Console.ReadLine();}
  1.    Hello c Sharp
  2.    HellocSharp
  3.    Compile time error
  4.    Hello
 Discuss Question
Answer: Option A. -> Hello c Sharp


Here '+' operator works as concatenation for strings.
Output : Hello c Sharp


Question 8. What will be the output of the following set of code?class sum    {     public int x;     public int y;     public  int add (int a, int b)    {        x = a + b;        y = x + b;        return 0;    }}    class Program{    static void Main(string[] args)    {        sum obj1 = new sum();        sum obj2 = new sum();           int a = 2;        obj1.add(a, a + 1);        obj2.add(5, a);        Console.WriteLine(obj1.x + "  " + obj2.y);             Console.ReadLine();    }}
  1.    6, 9
  2.    5, 9
  3.    9, 10
  4.    3, 2
 Discuss Question
Answer: Option B. -> 5, 9


Here, a = 2, a + 1 = 2 + 1 = 3.
So, a = 2, b = 3.
x = 2 + 3 = 5.
y = 5 + 3 = 8.
Similarly, a = 5, b = a + 1 = 4.
y = 5 + 4 = 9.
Output : 5, 9.


Question 9. Which of the following job is done by the instruction ++*p for an integer pointer p?
  1.    increment value contained at address p
  2.    increment address contained in p
  3.    Both 'a' and 'b'
  4.    Neither 'a' nor 'b'
 Discuss Question
Answer: Option A. -> increment value contained at address p


class UnsafeCode

{

unsafe static void Main()

{

int n = 10;

int* p = &n;

Console.WriteLine(*p);

}

}

Output : 10 + 1 = 11.


Question 10. what will be the output of code snippet?class UnsafeCode {     unsafe static void Main()     {         char[] arr = { 'A', 'B', 'C', 'D', 'E' };         fixed (char* P = arr)         {             int i;             for (i = 0 ;i < 5 ;i++)             if (*P % 2 == 0)             ++*P;             else             (*P)++;             Console.WriteLine(arr);         }         Console.ReadLine();     } }
  1.    ACCEE
  2.    FBCDE
  3.    BBDDF
  4.    BBCEE
 Discuss Question
Answer: Option B. -> FBCDE


Output:FBCDE


Latest Videos

Latest Test Papers