Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. Select the output for the following set of code : static void Main(string[] args)  {      int i = 0;      if (i == 0)      {          goto label;      }      label: Console.WriteLine("HI...");      Console.ReadLine();  }
  1.    Hi"¦infinite times
  2.    Code runs prints nothing
  3.    Hi Hi
  4.    Hi"¦
 Discuss Question
Answer: Option A. -> Hi"¦infinite times


for i = 0 ,if condition is satisfied as (i == 0).So,label statement is printed.
Output : Hi


Question 2. Select output for the following set of code :
static void Main(string[] args) {     int i, s = 0, a = 1, d;     i = Convert.ToInt32(Console.ReadLine());     do     {         d = i % (2 * 4);         s = s + d * a;     }while ((Convert.ToInt32(i = i / (2 * 4))) != 0 && (Convert.ToBoolean(Convert.ToInt32((a) = (a * 10)))));     Console.WriteLine(s);     Console.ReadLine(); }enter i = 342.
  1.    It finds binary equivalent of i
  2.    It finds octal equivalent of i
  3.    It finds sum of digits of i
  4.    It finds reverse of i
 Discuss Question
Answer: Option B. -> It finds octal equivalent of i


None.
Output : i = 342.
s = 526.


Question 3. Select the output for the following set of code:
static void Main(string[] args) {     int i, s = 0;     for (i = 1; i <= 10; s = s + i, i++);     {         Console.WriteLine(s);     }     Console.ReadLine(); }
  1.    Code report error
  2.    Code runs in infinite loop condition
  3.    Code gives output as 0 1 3 6 10 15 21 28 36 45
  4.    Code give output as 55
 Discuss Question
Answer: Option D. -> Code give output as 55


Since occurrence of termination symbol(;) at end of for loop.
Output: 55.


Question 4. Select the output for the following set of code :
 static void Main(string[] args)  {      int i = 0, j = 0;      l1: while (i < 2)      {            i++;          while (j < 3)          {              Console.WriteLine("loop\n");              goto l1;          }       }      Console.ReadLine();  }
  1.    loop is printed infinite times
  2.    loop
  3.    loop loop
  4.    Compile time error
 Discuss Question
Answer: Option C. -> loop loop


Since outer while loop i.e while(i

Question 5. Correct syntax for do while loop is :
  1.    do;   {    statement;   }while (condition);
  2.    do(condition)   {     statement;   }while;
  3.    do   {     statement;   }while (condition)
  4.    do   {        statement;   }while (condition);
 Discuss Question
Answer: Option D. -> do   {        statement;   }while (condition);


By definition
Output:do
{
statement;
}while (condition);


Question 6. Which statement is correct among the mentioned statements?
1. The for loop works faster than a while loop2. for( ; ; )implements an infinite loop
  1.    Only 1 is correct
  2.    Only 2 is correct
  3.    Both 1 and 2 are correct
  4.    Both 1 and 2 are incorrect
 Discuss Question
Answer: Option B. -> Only 2 is correct




Question 7. What is the output for the following code ?
static void Main(string[] args) {     int a = 15, b = 10, c = 1;     if (Convert.ToBoolean(a) && (b > c))     {         Console.WriteLine("cquestionbank");     }     else     {         break;     } }
  1.    cquestionbank
  2.    It will print nothing
  3.    Compile time error
  4.    Run time error
 Discuss Question
Answer: Option C. -> Compile time error


Keyword "break is not part of if-else statement.This keyword is used in case of loop or switch case statement.


Question 8. What is the output for the following code ?
static void Main(string[] args)  {        int a = 5;      if (Convert.ToBoolean((.002f) -(0.1f)))      Console.WriteLine("Sachin Tendulkar");      else if (a == 5)      Console.WriteLine("Rahul Dravid");      else      Console.WriteLine("Ms Dhoni");      Console.ReadLine();  }
  1.    Rahul Dravid
  2.    Sachin Tendulkar
  3.    Ms Dhoni
  4.    Warning : Unreachable Code
 Discuss Question
Answer: Option B. -> Sachin Tendulkar


(0.002 “ 0.1f) not equivalent to zero hence it is true. So,only first if clause will execute and print:Sachin Tendulkar on console.As,first condition is always true so no else if statement will be executed. Output: Sachin Tendulkar


Question 9. Select the output for the following set of Code:
 static void Main(string[] args)  {      int n, r;      n = Convert.ToInt32(Console.ReadLine());      while (n > 0)      {          r = n % 10;          n = n / 10;          Console.WriteLine(+r);      }      Console.ReadLine();  } for n = 5432.
  1.    3245
  2.    2354
  3.    2345
  4.    5423
 Discuss Question
Answer: Option C. -> 2345


Reverse of number using while loop.
Output: 2345.


Question 10. Select the output for the following set of code :
 static void Main(string[] args)  {      int  i = 9 , j = 7;      switch (i - j + 3)      {      case 9: 7:          j += 6;          break;      case 5:          i -= 4;          break;      }      Console.WriteLine(i + "\n" + j);      Console.ReadLine();  }
  1.    5 7
  2.    9 13
  3.    Compile time error
  4.    9 7
 Discuss Question
Answer: Option C. -> Compile time error


Invalid expression'7:' in case 9:7:.


Latest Videos

Latest Test Papers