Govt Exams
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 :.
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 break statement exits only the innermost loop it is in. To exit multiple nested loops, you need multiple break statements or use goto.
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.
A for loop with an empty body is valid syntax in C. The loop executes for the specified iterations but performs no operations in each iteration.
Without a break statement, execution continues to the next case (fall-through behavior). This is a common source of bugs if not intentional.
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.
A do-while loop executes the body at least once before checking the condition. A while loop checks the condition first, so it may not execute at all.