Govt Exams
Function declaration syntax is: return_type function_name(parameter_list);
In C, functions are defined by specifying the return type followed by the function name and parameters. No specific 'function' keyword is used.
Functions allow code reusability, modularity, and easier maintenance. They break down complex problems into smaller, manageable pieces.
int x = 5;
do {
printf("%d ", x);
x--;
} while(x > 0);
What will be the output?
The do-while loop executes at least once. x starts at 5, prints 5, decrements to 4, and continues while x > 0. Loop executes for x = 5,4,3,2,1 and exits when x becomes 0.
break statement terminates the loop completely, whereas continue statement skips the remaining statements in the current iteration and moves to the next iteration of the loop.
goto is legal in C but discouraged as it can create hard-to-follow code paths. It's acceptable in limited contexts like error handling.
The ternary operator (condition ? true_value : false_value) is a concise alternative to if-else for simple conditional assignments.
do-while executes the body first, then checks the condition, ensuring at least one execution.
The for loop syntax is for(init; condition; increment) allowing all three components in one statement.
continue skips the current iteration of the innermost loop and moves to the next iteration, while break exits the loop entirely.