250+ TOP MCQs on Switch Statements and Answers

C helps anyone preparing for HCL and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear HCL interviews on C Programming language.

Here is a listing of C Objective Questions on “Switch Statements” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     const int a = 1,  b = 2;
  3.     int main()
  4.     {
  5.         int x = 1;
  6.         switch (x)
  7.         {
  8.            case a:
  9.               printf("yes ");
  10.            case b:
  11.               printf("non");
  12.               break;
  13.         }
  14.     }

a) yes no
b) yes
c) no
d) Compile time error
Answer: d
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     #define max(a) a
  3.     int main()
  4.     {
  5.         int x = 1;
  6.         switch (x)
  7.         {
  8.            case max(2):
  9.               printf("yesn");
  10.            case max(1):
  11.               printf("non");
  12.               break;
  13.         }
  14.     }

a) yes no
b) yes
c) no
d) Compile time error
Answer: c
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         switch (printf("Do"))
  5.         {
  6.            case 1:
  7.               printf("Firstn");
  8.               break;
  9.            case 2:
  10.               printf("Secondn");
  11.               break;
  12.            default:
  13.               printf("Defaultn");
  14.               break;
  15.         }
  16.     }

a) Do
b) DoFirst
c) DoSecond
d) DoDefault
Answer: c
Clarification: None.

4. Comment on the output of the following C code.

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 1;
  5.         switch (a)
  6.         case 1:
  7.             printf("%d", a);
  8.         case 2:
  9.             printf("%d", a);
  10.         case 3:
  11.             printf("%d", a);
  12.         default:
  13.             printf("%d", a);
  14.     }

a) No error, output is 1111
b) No error, output is 1
c) Compile time error, no break statements
d) Compile time error, case label outside switch statement
Answer: d
Clarification: None.

5. Which datatype can accept the switch statement?
a) int
b) char
c) long
d) all of the mentioned
Answer: d
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 1;
  5.         switch (a)
  6.         {
  7.            case a:
  8.               printf("Case A ");
  9.            default:
  10.               printf("Default");
  11.         }
  12.     }

a) Output: Case A
b) Output: Default
c) Output: Case A Default
d) Compile time error
Answer: d
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     switch (ch)
  3.     {
  4.        case 'a':
  5.        case 'A':
  6.           printf("true");
  7.     }

a) if (ch == ‘a’ && ch == ‘A’) printf(“true”);
b)

if (ch == 'a')
if (ch == 'a') printf("true");

c) if (ch == ‘a’ || ch == ‘A’) printf(“true”);
d) none of the mentioned
Answer: c
Clarification: None.

  250+ TOP MCQs on Overview of DNA Repair and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top