Log In Register

Units


Switch Statements - Questions and Answers

 

Practice these Switch Statements under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Switch Statements for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Switch Statements of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Switch Statements.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Switch Statements under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Switch Statements topic of C Programming:

 

1.

What is the output of this C code(When 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char *ch;
  5.         printf("enter a value btw 1 to 3:");
  6.         scanf("%s", ch);
  7.         switch (ch)
  8.         {
  9.         case "1":
  10.             printf("1");
  11.             break;
  12.         case "2":
  13.             printf("2");
  14.             break;
  15.         }
  16.     }

Answer: Option C

Explanation:

2.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         switch (printf("Do"))
  5.         {
  6.         case 1:
  7.             printf("First\n");
  8.             break;
  9.         case 2:
  10.             printf("Second\n");
  11.             break;
  12.         default:
  13.             printf("Default\n");
  14.             break;
  15.         }
  16.     }

Answer: Option B

Explanation:

3.

Comment on the output of this C code?

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

Answer: Option A

Explanation:

4.

What is the output of this C code?

  1.     #include <stdio.h>
  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("no\n");
  12.             break;
  13.         }
  14.     }

Answer: Option A

Explanation:

5.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         float f = 1;
  5.         switch (f)
  6.         {
  7.         case 1.0:
  8.             printf("yes\n");
  9.             break;
  10.         default:
  11.             printf("default\n");
  12.         }
  13.     }

Answer: Option A

Explanation:

6.

What is the output of this C code(When 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%d", &ch);
  7.         switch (ch, ch + 1)
  8.         {
  9.         case 1:
  10.             printf("1\n");
  11.             break;
  12.         case 2:
  13.             printf("2");
  14.             break;
  15.         }
  16.     }

Answer: Option C

Explanation:

7.

What is the output of this C code(When 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%d", &ch);
  7.         switch (ch)
  8.         {
  9.         case 1:
  10.             printf("1\n");
  11.         default:
  12.             printf("2\n");
  13.         }
  14.     }

Answer: Option B

Explanation:

8.

What is the output of this C code(When 2 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%d", &ch);
  7.         switch (ch)
  8.         {
  9.         case 1:
  10.             printf("1\n");
  11.             break;
  12.             printf("hi");
  13.         default:
  14.             printf("2\n");
  15.         }
  16.     }

Answer: Option A

Explanation:

9.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 1, b = 1;
  5.         switch (a)
  6.         {
  7.         case a*b:
  8.             printf("yes ");
  9.         case a-b:
  10.             printf("no\n");
  11.             break;
  12.         }
  13.     }

Answer: Option B

Explanation:

10.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 97;
  5.         switch (x)
  6.         {
  7.         case 'a':
  8.             printf("yes ");
  9.             break;
  10.         case 97:
  11.             printf("no\n");
  12.             break;
  13.         }
  14.     }

Answer: Option B

Explanation:

11.

Comment on the output of this C code?

  1.     #include <stdio.h>
  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.     }

Answer: Option A

Explanation:

12.

Comment on the output of this C code?

  1.     #include <stdio.h>
  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.     }

Answer: Option A

Explanation:

13.

Switch statement accepts.

Answer: Option D

Explanation:

14.

What is the output of this C code(when 1 is entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double ch;
  5.         printf("enter a value btw 1 to 2:");
  6.         scanf("%lf", &ch);
  7.         switch (ch)
  8.         {
  9.         case 1:
  10.             printf("1");
  11.             break;
  12.         case 2:
  13.             printf("2");
  14.             break;
  15.         }
  16.     }

Answer: Option D

Explanation:

15.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define max(a) a
  3.     int main()
  4.     {
  5.         int x = 1;
  6.         switch (x)
  7.         {
  8.         case max(2):
  9.             printf("yes\n");
  10.         case max(1):
  11.             printf("no\n");
  12.             break;
  13.         }
  14.     }

Answer: Option B

Explanation: