Govt Exams
goto cannot jump across function boundaries. It can only jump within the same function to a labeled statement either forward or backward.
The 'break' statement is used to exit or terminate a loop immediately. 'continue' skips the current iteration, 'exit' terminates the entire program.
int x = 1, y = 2;
if (x < y) {
x++; y--;
if (x == y)
printf("Equal");
else
printf("NotEqual");
}
x=1, y=2. Since 1 < 2, x becomes 2 and y becomes 1. Now x != y, but after operations x=2, y=1. Wait: x++ makes x=2, y-- makes y=1. So x==y is false, printing 'NotEqual'. Rechecking: 1 < 2 is true, so enter if. x becomes 2, y becomes 1. 2 == 1 is false, so else executes, printing 'NotEqual'.
continue is the C keyword that jumps to the next iteration of the loop.
for (int i = 0; i < 5; i++) {
if (i % 2 == 0) continue;
printf("%d ", i);
}
continue skips even numbers. Loop prints only odd values: 1 and 3.
int i = 0;
while (i < 3) {
printf("%d ", i++);
}
i starts at 0. Loop prints i then increments: prints 0, then 1, then 2. When i becomes 3, condition fails.
goto transfers program control to a labeled location, though it's discouraged for code readability.
for (int i = 1; i
Nested loops: outer i=1,2,3; inner j=1,2. Prints products: 1*1=1, 1*2=2 (newline), 2*1=2, 2*2=4 (newline), etc.
Since 5 > 3 is true, the ternary operator returns 10, so x = 10.
int n = 1;
do {
printf("%d ", n);
n++;
} while (n > 5);
The do-while executes once (prints 1), then n becomes 2. Since 2 > 5 is false, the loop exits.