recategorized by
634 views
4 votes
4 votes

Consider the following C program given below.

#include<stdio.h>
main() {
    int a = 4;
    switch (a) {
    a--;
    case 4:
        printf("Science ");
        break;
    default:
        printf("Technology ");
    case 3:
        printf("Knowledge ");
    case 2:
        printf("Philosophy");
    }
}

What will be the output of the program?

  1. Science
  2. Knowledge Philosophy
  3. Technology Knowledge Philosophy
  4. Science Knowledge
recategorized by

1 Answer

2 votes
2 votes
The statements outside “case” but inside “switch” are never executed. Code may get compiled but those statements would still be unreachable and never execute.

We can think of switch as “goto” statements and jumping directly to those cases. Anything between is ignored.

Hence, a remains 4 and case 4 is executed.
Answer:

Related questions

3 votes
3 votes
3 answers
1