Govt Exams
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.
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.
The 'break' statement is used to exit or terminate a loop prematurely. 'exit' terminates the entire program, while 'return' exits functions.
The if-else-if chain allows testing multiple different conditions sequentially. switch is used for a single expression with multiple values.
for(int i=0; i<10; i++) correctly iterates from 0 to 9 (10 iterations total). Using i<=10 would iterate 11 times, and starting from 1 would skip 0.
The 'default' keyword in a switch statement provides code to execute when no case values match the switch expression.
The if statement executes a block of code conditionally. Loops repeat code, and switch cases are for multi-way branching based on a single expression.
The ternary operator evaluates the condition (x > 5). Since 3 is not greater than 5, the expression evaluates to false, and the false part executes, setting y to 20.
The 'continue' statement skips the remaining statements of the current iteration and moves to the next iteration. In nested loops, it affects only the innermost loop.