Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 771–780 of 1,000
Topics in C Programming
Q.771 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.772 Easy Control Flow
What is the correct syntax for a for loop that iterates from 0 to 9?
A for(int i=0; i
B for(int i=0; i
C for(int i=1; i
D for(int i=0; i
Correct Answer:  B. for(int i=0; i
EXPLANATION

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.

Take Test
Q.773 Easy Control Flow
In a switch statement, which keyword provides a default case if no cases match?
A else
B default
C otherwise
D case default
Correct Answer:  B. default
EXPLANATION

The 'default' keyword in a switch statement provides code to execute when no case values match the switch expression.

Take Test
Q.774 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.775 Easy Control Flow
Which control flow structure allows execution of code only if a certain condition is met?
A for loop
B if statement
C switch case
D while loop
Correct Answer:  B. if statement
EXPLANATION

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.

Take Test
Q.776 Easy Control Flow
In the expression (x > 5) ? (y = 10) : (y = 20), what does y equal if x is 3?
A 10
B 20
C 3
D Undefined
Correct Answer:  B. 20
EXPLANATION

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.

Take Test
Q.777 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.778 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
Q.779 Easy Control Flow
In a nested loop structure, which statement will skip only the inner loop's current iteration?
A break
B continue
C next
D skip
Correct Answer:  B. continue
EXPLANATION

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.

Take Test
Q.780 Easy Control Flow
What is the primary difference between a while loop and a do-while loop?
A while checks condition before execution; do-while checks after
B do-while is faster than while
C while supports multiple conditions; do-while doesn't
D There is no functional difference
Correct Answer:  A. while checks condition before execution; do-while checks after
EXPLANATION

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.

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