adplus-dvertising

Welcome to the Control Instructions MCQs Page

Dive deep into the fascinating world of Control Instructions with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Control Instructions, a crucial aspect of C# programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Control Instructions, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Control Instructions. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Control Instructions. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Control Instructions MCQs | Page 3 of 9

Q21.
Which of the following statements is correct about the C#.NET code snippet given below?

int i, j, id = 0; switch (id)
{ 
    case i:
        Console.WriteLine("I am in Case i");
        break; 
    
    case j:
        Console.WriteLine("I am in Case j");
        break;
}
Discuss
Answer: (a).The compiler will report case i and case j as errors since variables cannot be used in cases.
Q22.
Select the output for the following set of code :
static void Main(string[] args)
 {
     int i = 30;
     int j = 25 % 25;
     if (Convert.ToBoolean(Convert.ToInt32(i = j)))
     {
         Console.WriteLine("In if");
     }
     else
     {
         Console.WriteLine("In else");
     }
     Console.WriteLine("In main");
     Console.ReadLine();
 }
Discuss
Answer: (d).In else
In main
Q23.
Select output for the following set of Code:
static void Main(string[] args)
 {
     int i;
     int b = 8, a = 32;
     for (i = 0; i <= 10; i++)
     {
         if ((a / b * 2)== 2)
         {
             Console.WriteLine( i + " ");
             continue;
         }
         else if (i != 4)
             Console.Write(i + " ");
         else
             break;
    }
    Console.ReadLine();
 }
Discuss
Answer: (c).0 1 2 3
Q24.
Select the output for the following set of Code. Which of the following conditions are true ?
static void Main(string[] args)
 {
     Console.WriteLine("Enter a letter:");
     char c = (char)Console.Read();
     if (Char.IsDigit(c) == true)
         Console.WriteLine("A number");
     else if (char.IsLower(c) == true)
         Console.WriteLine("A lower case letter");
     else if (char.IsUpper(c) == true)
         Console.WriteLine("An upper case letter");
     Console.ReadLine();
 }
 1. Enter a letter :
    a
    An upper case letter
 2. Enter a letter :
    A
    An upper case letter
 3. Enter a letter :
    2
    A number
 4. Enter a letter :
    2
    A lower case letter.
Discuss
Answer: (d).b ,c
Q25.
Select the output for the following set of Code:
static void Main(string[] args)
  {
      int i, j;
      for (i = 2; i >= 0; i--)
      {
          for (j = 0; j <= 2; j++)
          {
              if (i == j)
              {
                  Console.WriteLine("1");
              }
              else
              {
                  Console.WriteLine("0");
              }
         }
         Console.WriteLine("\n");
         Console.ReadLine();
      }
  }
Discuss
Answer: (c).0 0 1
0 1 0
1 0 0
Q26.
Select the correct ‘if statement’ to be filled in the given set of code :
static void Main(string[] args)
 {
     int []num = {50, 65, 56, 88, 43, 52};
     int even = 0, odd = 0;
     for (int i = 0 ;i < num.Length ;i++)
     {
          /*___________________________*/
     }   
     Console.WriteLine("Even Numbers:" +even);
     Console.WriteLine("Odd Numbers:" +odd);
     Console.ReadLine();
 }

a)

if ((num % 2) == 0)
   {
       even += 1;
   }
   else
   {
       odd += 1;
   }

b)

 if((num * i) == 0)
   {
       even += 1;
   }
   else
   {
       odd += 1;
   }

c)

if(num[i] % 2 == 0)
    {
        even += 1;
    }
    else
    {
        odd += 1;
    }

d)

 if(num[i] % 2 = 0)
    {
        even += 1;
    }
    else
    {
        odd += 1;
    }

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (c).c
Q27.
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;
     }
 }
Discuss
Answer: (c).Compile time error
Q28.
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();
  }
Discuss
Answer: (b).Sachin Tendulkar
Q29.
Select the output for the following set of Code :
static void Main(string[] args)
  {   
      int a = -1;
      int b = -1;
      if (Convert.ToBoolean (++a = ++b))
      Console.WriteLine("a");
      else
      Console.WriteLine("b");
      Console.ReadLine();
  }
Discuss
Answer: (c).Compile time error
Q30.
Select the output for the following set of Code :
static void Main(string[] args)
  {
      int a = 5, b = 10;
      if (Convert.ToBoolean(Convert.ToInt32(0xB)))
      if (Convert.ToBoolean(Convert.ToInt32(022)))
      if (Convert.ToBoolean(Convert.ToInt32('\xeb')))
      Console.WriteLine("java");
      else ;
      else ;
      else ;
  }
Discuss
Answer: (c).java
Page 3 of 9

Suggested Topics

Are you eager to expand your knowledge beyond C# programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!