C Programming Language Objective Type Questions With Answers

Multiple choice and objective type questions base on the switch control structure of C language.  

1) When we use the case control structure ?
  1. To choose one from multiple alternatives
  2. To switch from one instruction to another
  3. To make the execution fast
  4. None of above
Show/Hide Answer
Answer = A
2) The case keyword is followed by ?
  1. Float values
  2. Character values
  3. integer values
  4. Both b and c
Show/Hide Answer
Answer = D
3) What will be the output of following code ?
   #include<stdio.h>
   void main( )
   {
        char suite =3;
        switch(suite)
        {
               case 1: 
                        printf("ALL QUIZ");
               case 2:
                        printf("All quiz is great");
               default:
                        printf("All quiz contains MCQs");
         }
         printf("Are you like All quiz ?");
   }
     
  1. ALL QUIZ
  2. All quiz is great
  3. All quiz contains MCQs
  4. All quiz is great Are you like Al quiz ?
Show/Hide Answer
Answer = D 
Explanation: Because the condition within the switch does not match any case so the default block will be executed. After then the control will be transferred to out of the switch and print statement will be executed.
4) What will be the output of following code ?
       void main( )
       {
            int c=3;
            switch(c)
            {
                case '3':
                      printf("Hi");
                      break;
                case 3:
                      printf("Hello");
                      break;
                 default:
                      printf("How r u ?");
            }
       }
                
 
  1. Hi
  2. Hello
  3. How r u ?
  4. None of above
Show/Hide Answer
Answer =  B
5) What will be the output of following program ?
       void main( )
       {
          int 1=3;
          switch(i)
          {
               case 0:
                    printf("I am here");
               case 1+0:
                    printf("I m in second case");
               case 4/2:
                    printf("I m in third case");
               case 8%5:
                    printf("Good bye");
           }
        } 
  1. All case statements will be executed
  2. I am here
  3. Good bye
  4. I am in third case
Show/Hide Answer
Answer = C 
6) What will be the output of following ?
            void main( )
            {
                  int suite =1;
                  switch(suite);
                 {
                       case 0:
                             printf("Its morning time");
                       case 1: 
                             printf("Its evening time");
                 }
            } 
  1. Error
  2. Its morning time
  3. Its evening time
  4. None of above
Show/Hide Answer
Answer = A 
Explanation: The code will generate an error that the case is outside switch. It is because of the semicolon after the switch statement.


Do You Like This? Please take 5 seconds to share with your firends.

1 comments:

Unknown said...

Wrong ans in question 3.. The option(D) must be modified to "All quiz contains MCQs Are you like All quiz ?"

Post a Comment