Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 381–390 of 499
Topics in C Programming
Q.381 Medium Control Flow
What will be the output of the following code?
int i = 0;
while(i < 3) {
printf("%d ", i++);
if(i == 2) continue;
}
A 0 1 2
B 0 1
C 0 2
D Infinite loop
Correct Answer:  A. 0 1 2
EXPLANATION

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

Take Test
Q.382 Medium Control Flow
Which statement is best suited for implementing a menu-driven program with exact matching?
A if-else chain
B while loop
C switch statement
D for loop
Correct Answer:  C. switch statement
EXPLANATION

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.

Take Test
Q.383 Medium Control Flow
What is the scope of a variable declared in the initialization section of a for loop?
A Global scope
B Function scope
C Loop scope only
D File scope
Correct Answer:  C. Loop scope only
EXPLANATION

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.

Take Test
Q.384 Medium Control Flow
In a switch statement, case values must be of which type?
A Any type
B Integer or character constant
C String only
D Float or double
Correct Answer:  B. Integer or character constant
EXPLANATION

Switch case values must be constant integral expressions (int, char, enum). Floating-point values and strings (in C89/C90) are not allowed.

Take Test
Q.385 Medium Control Flow
In control flow, which statement is used to explicitly exit from a program?
A break
B exit()
C return
D halt
Correct Answer:  B. exit()
EXPLANATION

The exit() function terminates the entire program and returns control to the operating system. break exits loops, and return exits functions.

Take Test
Q.386 Medium Control Flow
How many times will a do-while loop execute if the condition is initially false?
A Zero times
B At least once
C Depends on the body
D Infinite times
Correct Answer:  B. At least once
EXPLANATION

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.

Take Test
Q.387 Medium Control Flow
Which of the following correctly uses the conditional (ternary) operator?
A (condition) : (true) ? (false)
B (condition) ? (true) : (false)
C (true) ? (condition) : (false)
D (condition) ? (false) : (true)
Correct Answer:  B. (condition) ? (true) : (false)
EXPLANATION

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 :.

Take Test
Q.388 Medium Control Flow
What is the output of executing break in a nested loop context?
A Breaks out of all nested loops
B Breaks out of the innermost loop only
C Skips the current iteration of the inner loop
D Causes compilation error
Correct Answer:  B. Breaks out of the innermost loop only
EXPLANATION

The break statement exits only the innermost loop it is in. To exit multiple nested loops, you need multiple break statements or use goto.

Take Test
Q.389 Medium Control Flow
What will be the behavior of a for loop with an empty body and no statements inside braces?
A Compilation error
B Infinite loop
C Loop executes normally with no operations
D Loop is skipped entirely
Correct Answer:  C. Loop executes normally with no operations
EXPLANATION

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.

Take Test
Q.390 Medium Control Flow
Consider a switch statement with multiple cases. If a case matches and break is omitted, what happens?
A Program terminates
B Execution falls through to the next case
C Current case executes twice
D Compilation error occurs
Correct Answer:  B. Execution falls through to the next case
EXPLANATION

Without a break statement, execution continues to the next case (fall-through behavior). This is a common source of bugs if not intentional.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips