Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 221–230 of 303
Topics in C Programming
Q.221 Easy Control Flow
What will be the result?
for(int i = 1; i
A 1 2 3 4
B 1 2
C 1 2 3
D 2 3 4
Correct Answer:  B. 1 2
EXPLANATION

When i=3, break executes and exits the loop immediately. Only i=1 and i=2 are printed. Output: 1 2

Take Test
Q.222 Easy Control Flow
In the ternary operator (? :), what happens if the condition is false?
A The first expression is evaluated
B The second expression is evaluated
C Both expressions are evaluated
D No expression is evaluated
Correct Answer:  B. The second expression is evaluated
EXPLANATION

The ternary operator syntax is: condition ? true_expr : false_expr. If condition is false, false_expr is evaluated.

Take Test
Q.223 Easy Control Flow
Analyze the code: What happens when condition in if statement is false?
if(0) { statements; } else { statements; }
A Program terminates
B Else block executes
C Infinite loop occurs
D Syntax error
Correct Answer:  B. Else block executes
EXPLANATION

When the if condition is false (0 is false in C), the else block executes. This is basic if-else control flow.

Take Test
Q.224 Easy Control Flow
Which keyword is used to exit a loop prematurely in C?
A exit
B break
C return
D stop
Correct Answer:  B. break
EXPLANATION

The 'break' statement is used to exit or terminate a loop prematurely. 'exit' terminates the entire program, while 'return' exits functions.

Take Test
Q.225 Easy Control Flow
Which control structure allows checking multiple conditions in sequence using else-if?
A for loop
B switch statement
C if-else-if chain
D do-while loop
Correct Answer:  C. if-else-if chain
EXPLANATION

The if-else-if chain allows testing multiple different conditions sequentially. switch is used for a single expression with multiple values.

Take Test
Q.226 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.227 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.228 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.229 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.230 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
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