What is the purpose of the 'break' statement in C?
A. End the program
B. Skip the loop
C. Exit a function
D. Exit a loop
Answer: Option D
Solution(By Examveda Team)
The purpose of the 'break' statement in C is to exit a loop. When 'break' is encountered within a loop (such as 'for' or 'while' loop), it immediately terminates the loop and continues with the next statement after the loop's body.So, the correct answer is:
Option D: Exit a loop
Here's an example of using the 'break' statement to exit a loop in C:
for (int i = 1; i <= 10; i++) {
if (i == 5) {
break; // Exit the loop when i is equal to 5
}
printf("%d ", i);
}
Related Questions on C Fundamentals
What is the primary purpose of a function prototype in C?
A. Declare a variable
B. Declare a function
C. Define a function
D. Assign a value
What is the correct syntax for declaring a variable in C?
A. int variable_name;
B. variable_name = 5;
C. variable_name int;
D. int = variable_name;
Join The Discussion