LearnFrenzy
Sign in Take a free test

Control Instructions · Predict the Output · Question 3

switch with no break statements – output Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int n = 2;
    switch (n) {
    case 1: printf("one ");
    case 2: printf("two ");
    case 3: printf("three ");
    default: printf("other");
    }
    printf("\n");
    return 0;
}
  • A two three other Correct
  • B two
  • C two other
  • D one two three other
Correct Answer: Option A

Execution enters at case 2 and, with no break anywhere, falls through every following label, including default.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links