Question discussion

What is the output of the following C program?#include int main() { int i; for (i = 0; i < 6; i++) { if (i == 2) continue; if (i == 4) brea…

1789Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int i;
    for (i = 0; i < 6; i++) {
        if (i == 2) continue;
        if (i == 4) break;
        printf("%d", i);
    }
    printf(" %d", i);
    return 0;
}
  • A0123 4
  • B0134 4
  • C013 5
  • D013 4
Correct answer: D

Explanation

The value 2 is skipped by continue and the loop stops at i = 4 through break, so it prints 0, 1, 3 and then the final value 4.

Discussion 0

Nobody has replied yet. Start the discussion!