C# Programming - Control Instructions

Exercise :: Control Instructions - General Questions

  • Control Instructions - General Questions
6. 

What will be the output of the C#.NET code snippet given below?

int val;
for (val = -5; val <= 5; val++)
{
    switch (val)
    {
        case 0:
            Console.Write ("India"); 
            break;
    }
    
    if (val > 0)
        Console.Write ("B"); 
    else if (val < 0)
        Console.Write ("X");
}

A. XXXXXIndia
B. IndiaBBBBB
C. XXXXXIndiaBBBBB
D. BBBBBIndiaXXXXX
E. Zero

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

7. 

What will be the output of the C#.NET code snippet given below?

char ch = Convert.ToChar ('a' | 'b' | 'c'); 
switch (ch)
{
    case 'A': 
    case 'a':
    Console.WriteLine ("case A | case a");
    break;
    
    case 'B': 
    case 'b':
    Console.WriteLine ("case B | case b");
    break;
    
    case 'C':
    case 'c':
    case 'D':
    case 'd':
    Console.WriteLine ("case D | case d");
    break;
}

A. case A | case a
B. case B | case b
C. case D | case d
D. Compile Error
E. No output

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

8. 

Which of the following is the incorrect form of Decision Control instruction?

A.
if (Condition1) 
{// Some statement}
B.
if (Condition1) {// Some statement} 
else {// Some statement}
C.
if (Condition1) {// Some statement} 
else {// Some statement} 
else if ( Condition2){//Some statement}
D.
if ( Condition1 ) {// Some statement} 
else if ( Condition2 ) {// Some statement} 
else {// Some statement}
E.
if ( Condition1 ) {// Some statement} 
else if ( Condition2 ) {// Some statement} 
else if ( Condition3 ) {// Some statement} 
else {// Some statement}

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

9. 

Which of the following code snippets are the correct way to determine whether a is Odd or Even?

  1. int a;
    String res; 
    if (a % 2 == 0)
        res = "Even"; 
    else 
        res = "Odd";
  2. int a; 
    String res; 
    if (a Mod 2 == 0) 
        res = "Even"; 
    else
        res = "Odd";
  3. int a;
    Console.WriteLine(a Mod 2 == 0 ? "Even": "Odd");
  4. int a; 
    String res;
    a % 2 == 0 ? res = "Even" : res = "Odd";
    Console.WriteLine(res);

A. 1, 3
B. 1 Only
C. 2, 3
D. 4 Only
E. None of these

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

10. 

Which of the following can be used to terminate a while loop and transfer control outside the loop?

  1. exit while
  2. continue
  3. exit statement
  4. break
  5. goto

A. 1, 3
B. 2, 4
C. 3, 5
D. 4, 5
E. None of these

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.