Govt. Exams
Entrance Exams
'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
int i = 0;
while(i < 3) {
printf("%d ", i++);
if(i == 2) continue;
}
The loop prints 0, then i becomes 1. When i becomes 2, continue skips the rest but the loop continues. i becomes 3 and loop exits. Output: 0 1 2
A switch statement is ideal for menu-driven programs where you match user input against specific cases. It's more efficient and readable than multiple if-else statements for this purpose.
Variables declared in a for loop's initialization (e.g., for(int i=0; ...)) have block scope limited to that loop. They are not accessible outside the loop.
Switch case values must be constant integral expressions (int, char, enum). Floating-point values and strings (in C89/C90) are not allowed.
The exit() function terminates the entire program and returns control to the operating system. break exits loops, and return exits functions.
A do-while loop executes the body at least once before checking the condition. Even if the condition is false, the body executes one time.
The correct syntax is (condition) ? (value_if_true) : (value_if_false). The condition comes first, followed by ? and then the true and false values separated by :.
The break statement exits only the innermost loop it is in. To exit multiple nested loops, you need multiple break statements or use goto.