Entrance Exams
Govt. Exams
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.
for(int i = 1; i
continue skips when i==j. i=1: prints 12 (skips 11); i=2: prints 21 (skips 22). Output: 12 21
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 i = 0;
while(1) {
i++;
if(i > 5) break;
}
while(1) creates an infinite loop. i increments until i > 5 (i becomes 6), then break exits. Loop runs 6 iterations.
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
if(i + j == 1) continue;
printf("Done");
continue only affects the inner loop, not the outer. The loops complete normally and 'Done' is printed once after both loops finish.
if(1) if(0) printf("A"); else printf("B");
The else binds to the nearest if (inner if). Outer if(1) is true, inner if(0) is false, so else executes printing 'B'.