Govt Exams
int x = 1, y = 2;
if(x > y) printf("A");
else if(x < y) printf("B");
else printf("C");
Since x=1 and y=2, x>y is false, but x<y is true, so 'B' is printed. The else if condition matches.
Case labels must be constant integral expressions (int, char, etc.). Floating-point constants are not allowed as case labels.
for(int i = 1; i
When i=3, break executes and exits the loop immediately. Only i=1 and i=2 are printed. Output: 1 2
The ternary operator syntax is: condition ? true_expr : false_expr. If condition is false, false_expr is evaluated.
int x = 0;
for(int i = 1; i
continue skips even values. x accumulates: 1(i=1) + 3(i=3) + 5(i=5) = 9. Values i=2,4 are skipped.
if(0) { statements; } else { statements; }
When the if condition is false (0 is false in C), the else block executes. This is basic if-else control flow.
for(int i = 0; i < 3; i++) {
if(i == 1) goto skip;
printf("%d ", i);
}
skip: printf("End");
When i=1, goto skip jumps to the skip label, skipping the printf. i continues to 2 in the loop. Output: 0 2 End
int x = 5;
switch(x) {
case 5: printf("Five");
case 6: printf("Six");
default: printf("Default");
}
Without a break statement after case 5, control falls through to case 6 and default. This is called fall-through behavior in switch statements.
'goto' transfers control to the label specified, which can be anywhere in the program. It can jump out of nested structures to the labeled location.
for(int i = 1; i
The break statement only exits the inner loop. When i=2 and j=1, inner loop breaks. i=3 executes normally. Output: 11 31 32