Home Subjects C Programming Control Flow

C Programming
Control Flow

C language from basics to advanced placement prep

52 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 52
Topics in C Programming
Q.31 Medium Control Flow
In a nested loop, if we use 'goto' statement, where does the control transfer?
A To the label specified in goto statement
B To the outer loop only
C To the beginning of the loop
D To the next iteration
Correct Answer:  A. To the label specified in goto statement
EXPLANATION

'goto' transfers control to the label specified, which can be anywhere in the program. It can jump out of nested structures to the labeled location.

Test
Q.32 Medium Control Flow
What is the output of the following code?
for(int i = 1; i
A 11 21 31 32
B 11 12 31 32
C 11 31 32
D 11 12 21 31 32
Correct Answer:  C. 11 31 32
EXPLANATION

The break statement only exits the inner loop. When i=2 and j=1, inner loop breaks. i=3 executes normally. Output: 11 31 32

Test
Q.33 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

Test
Q.34 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.

Test
Q.35 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.

Test
Q.36 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.

Test
Q.37 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.

Test
Q.38 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.

Test
Q.39 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 :.

Test
Q.40 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.

Test
IGET
IGET AI
Online · Exam prep assistant
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