Govt Exams
For loop order: initialization → check condition → execute body → increment → repeat from condition check.
goto is valid in C but discouraged in modern programming as it reduces code readability. However, it has legitimate uses in cleanup code and error handling.
Ternary operator is short-circuit. If condition is true, expr1 evaluates and expr2 is skipped. If false, expr2 evaluates and expr1 is skipped.
goto statement allows unconditional jump to a labeled location. Though generally discouraged, it's valid in C and sometimes used for error handling.
Missing break causes fall-through behavior where execution continues to the next case label until a break or end of switch is encountered.
do-while loop checks the condition after executing the loop body, ensuring at least one execution. while loop checks before executing.
break and continue statements can only be used within loops or switch statements. Using break outside these constructs results in a compilation error.
int result = (5 > 3) ? 10 : 20;
The condition (5 > 3) is true, so the ternary operator evaluates and returns the true expression value: 10.
break completely exits/terminates the loop. continue skips the rest of current iteration and jumps to the next iteration.
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.