1. What is the primary characteristic of a 'while' loop in C?
a) The loop executes at least once
b) The condition is checked at the end of the loop
c) The loop may not execute at all if the condition is false initially
d) The loop executes an indefinite number of times
2. How does a 'do...while' loop differ from a 'while' loop in C?
a) The 'do...while' loop checks the condition at the beginning
b) The 'do...while' loop executes at least once regardless of the condition
c) The 'do...while' loop cannot use a break statement
d) The 'do...while' loop is faster than the 'while' loop
3. What is the correct syntax for a 'while' loop in C?
a) while condition { statements; }
b) while (condition) { statements; }
c) while (condition) statements;
d) Both b) and c) are correct
4. What is the correct syntax for a 'do...while' loop in C?
a) do { statements; } while (condition);
b) do (condition) { statements; };
c) do { statements; } until (condition);
d) do while (condition) { statements; };
5. Which type of loop is ideal when the number of iterations is not known in advance?
a) For loop
b) While loop
c) Do/while loop
d) Both b) and c) are suitable
6. In a 'while' loop, if the condition never becomes false, what happens?
a) The loop exits after a certain number of iterations
b) The loop continues indefinitely, creating an infinite loop
c) The loop skips to the next section of code
d) An error is thrown by the compiler
7. What will the following C code snippet print?
int i = 0;
while (i < 3) {
printf("%d", i);
i++;
}
a) 012
b) 123
c) 0123
d) An infinite number of 0s
8. Which of the following is a valid 'do...while' loop in C?
a) do { statements; } while condition;
b) do { statements; } while (condition)
c) do (condition) { statements; } while;
d) do { statements; } while (condition);
9. How can you exit a 'while' loop prematurely in C?
a) Using the 'stop' statement
b) Using the 'exit' statement
c) Using the 'break' statement
d) By setting the condition to false
10. What is the role of the 'continue' statement in a 'while' loop in C?
a) To exit the loop
b) To skip the current iteration and proceed to the next iteration
c) To pause the loop temporarily
d) To restart the loop from the beginning
11. What is the minimum number of times a 'do...while' loop is guaranteed to execute?
a) 0 times
b) 1 time
c) 2 times
d) Depends on the condition
12. Which of the following is an infinite loop in C?
a) while (1) { }
b) while (0) { }
c) do { } while (0);
d) for (;;) { }
13. What happens if the condition in a 'while' loop is always true?
a) The loop executes a fixed number of times
b) The loop executes only once
c) The loop executes indefinitely
d) The program terminates
14. Can a 'while' loop be used to iterate over an array in C?
a) Yes, using an index variable
b) No, 'while' loops cannot be used with arrays
c) Only if the array has a known fixed size
d) Only in combination with a 'for' loop
15. In a 'do...while' loop, where should the increment/decrement statement typically be placed?
a) Before the loop body
b) At the beginning of the loop body
c) At the end of the loop body
d) After the loop condition
Comments
Post a Comment