Q: Which of the following loop control statements is used to terminate a loop completely?
A.continue
B.break
C.exit
D.return
Correct Option: BExplanation:
Answer: b) break
Explanation: The break statement is used to terminate a loop completely.
Q: Which loop is best suited for scenarios where you want to repeat a block of code while a condition is true?
A. for loop
B. while loop
C. do-while loop
D. if-else loop
Correct Option: BExplanation:
The while loop repeatedly executes a block of code as long as the specified condition remains true.
Q: In a for loop, which part is optional?
A. Initialization
B. Condition
C. Increment/Decrement
D. All parts are mandatory
Correct Option: CExplanation:
While initialization and condition are mandatory in a for loop, the increment or decrement part is optional.
Q: Which of the following loop control statements is used to return a value from a function?
A.continue
B.break
C.exit
D.return
Correct Option: DExplanation:
Answer: d) return
Explanation: The return statement is used to return a value from a function.
Q: Which loop in C is used to execute a block of code at least once?
A. for loop
B. while loop
C. do-while loop
D. if-else loop
Correct Option: CExplanation:
The do-while loop executes the code block at least once before checking the loop condition. It is useful when you need to ensure the code block runs at least once.
Q: Which loop control statement is used to exit from the loop and transfer control to the statement immediately after the loop?
A. break
B. continue
C. return
D. exit
Correct Option: AExplanation:
The "break" statement is used to terminate the loop and continue execution after the loop's closing brace.
Q: Which of the following loop control statements is used to skip the current iteration of a loop and continue with the next iteration?
A.continue
B.break
C.exit
D.return
Correct Option: AExplanation:
Answer: a) continue
Explanation: The continue statement is used to skip the current iteration of a loop and continue with the next iteration.
Q: What is the purpose of the "do-while" loop?
A. To execute code based on a condition
B. To execute code repeatedly until a condition is false
C. To execute code at least once and then based on a condition
D. To execute code based on multiple conditions
Correct Option: CExplanation:
The "do-while" loop ensures that the code block is executed at least once before checking the loop condition for further execution.
Q: Which of the following loop control statements is used to terminate the current iteration of a loop and continue with the next iteration?
A.continue
B.break
C.exit
D.return
Correct Option: AExplanation:
Answer: a) continue
Explanation: The continue statement is used to skip the current iteration of a loop and continue with the next iteration.
Q: How many times the while loop will get executed if a short int is 2 byte wide?
#include
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0;
}
A.Infinite times
B.255 times
C.256 times
D.254 times
Correct Option: AExplanation:
Option B
The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.