Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 381–390 of 490
Topics in C Programming
Q.381 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.382 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.383 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.384 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.385 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.386 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
Q.387 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.

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

Test
Q.389 Medium Control Flow
Which of the following is NOT a valid use of the goto statement in C?
A Jumping forward to a label
B Jumping backward to a label
C Jumping across function boundaries
D Jumping to an error handling block
Correct Answer:  C. Jumping across function boundaries
EXPLANATION

goto cannot jump across function boundaries. It can only jump within the same function to a labeled statement either forward or backward.

Test
Q.390 Medium Control Flow
What does this code segment output?
for (int i = 0; i < 5; i++) {
if (i % 2 == 0) continue;
printf("%d ", i);
}
A 1 3
B 0 2 4
C 1 3 5
D 0 1 2 3 4
Correct Answer:  A. 1 3
EXPLANATION

continue skips even numbers. Loop prints only odd values: 1 and 3.

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