C Programming Multiple Choice Question MCQ
Categories: MCQS
Q1. What does the break statement do in a loop? A. Exits the loop B. Skips the current iteration C. Repeats the loop D. Does nothing Answer: Exits the loop Q2. What is the difference between for and while loops? A. Syntax B. Execution speed C. Functionality D. No difference Answer: Syntax Q3. In a switch statement, what happens if a break statement is omitted from a case? A. The program exits B. The case is skipped C. Fall-through to the next case D. Syntax error Answer: Fall-through to the next case Q4. What is the purpose of the continue statement in loops? A. Terminates the loop B. Skips to the next iteration C. Does nothing D. Exits the program Answer: Skips to the next iteration Q5. When is a do-while loop preferred over a while loop? A. When the condition is complex B. When the loop must execute at least once C. When the loop should not execute D. When the loop is infinite Answer: When the loop must execute at least once Q6. What will the following C code print? int main() { for(int i = 0; i < 3; i++) { printf("%d ", i); } return 0; } A. 0 1 2 B. 1 2 3 C. 0 1 2 3 D. 1 2 3 4 Answer: 0 1 2 Q7. What does this C code do? int main() { int i = 0; while(i < 5) { if(i == 2) break; printf("%d ", i); i++; } return 0; } A. Prints 0 1 2 B. Prints 0 1 C. Prints all numbers less than 5 D. Prints nothing Answer: Prints 0 1 Q8. What is the output of the following C code? int main() { int x = 0; do { printf("%d ", x); x++; } while(x < 3); return 0; } A. 0 1 2 B. 0 1 C. 1 2 3 D. No output Answer: 0 1 2 Q9. Pseudocode: SET num TO 10 IF num EQUALS 10 THEN PRINT "Ten" ELSE PRINT "Not Ten" A. Prints "Ten" B. Prints "Not Ten" C. Prints nothing D. Syntax error Answer: Prints "Ten" Q10. Pseudocode: SET x TO 5 WHILE x GREATER THAN 0 DO PRINT x DECREMENT x A. Prints numbers from 5 to 1 in descending order B. Prints 5 C. Prints 0 D. Syntax error Answer: Prints numbers from 5 to 1 in descending order Q11. Pseudocode: FOR i FROM 1 TO 5 PRINT i A. Prints numbers from 1 to 5 B. Prints numbers from 1 to 4 C. Prints 5 D. Syntax error Answer: Prints numbers from 1 to 5 Q12 Pseudocode: SET count TO 0 REPEAT PRINT count INCREMENT count UNTIL count EQUALS 3 A. Prints 0 1 2 3 B. Prints 0 1 2 C. Prints 3 D. Syntax error Answer: Prints 0 1 2 Q13. Pseudocode: SET i TO 0 WHILE i LESS THAN 10 IF i MOD 2 EQUALS 0 THEN CONTINUE INCREMENT i PRINT i END WHILE A. Prints odd numbers from 1 to 9 B. Prints even numbers from 0 to 8 C. Prints all numbers from 0 to 9 D. Syntax error Answer: Prints odd numbers from 1 to 9 Q14. Identify the error in this C code: int main() { int i = 0; while(i < 3) { i++; } printf("%d ", i); return 0; } A. Infinite loop B. Syntax error C. No error D. Prints nothing Answer: No error Q15. Spot the mistake: int main() { for(int i = 0; i < 5; i++) { if(i == 2) continue; printf("%d ", i); } return 0; } A. Infinite loop B. Skips printing 2 C. Syntax error D. No error Answer: Skips printing 2 Q16. What is the primary purpose of a function in C? A. Code reuse and modularity B. Error handling C. Memory management D. User interface creation Answer: Code reuse and modularity Q17. What does 'pass by value' mean in C? A. Passing a copy of the argument B. Passing the argument directly C. Passing the memory address D. Passing the variable type Answer: Passing a copy of the argument Q18. What is recursion in C? A. A function calling another function B. A function that has no return type C. A function calling itself D. A loop within a function Answer: A function calling itself Q19. What is the scope of a local variable in C? A. Inside the function in which it is declared B. Throughout the program C. Inside the file D. Throughout the function block where it is declared Answer: Inside the function in which it is declared Q20. What will be the output of the following C code? int main() { int num = 10; increment(num); printf("%d", num); return 0; } void increment(int n) { n++; } A. 10 B. 11 C. Error D. Nothing Answer: 10