Control Statements in C MCQ
C control statements test paper contains questions from decision statement: if-else and switch, loop statWhat is the purpose of control statements in programming?1. What is the purpose of control statements in programming?
a. To define variables
b. To control the flow of program execution
c. To declare functions
d. To print output
Correct Answer: b
2. Which control statement is used to repeat a block of code until a certain condition is met?
a. if statement
b. for loop
c. switch statement
d. do-while loop
Correct Answer: d
3. In a for loop, which part is optional?
a. Initialization
b. Condition
c. Increment/Decrement
d. None of the above
Correct Answer: a
4. What is the purpose of the break statement in a loop?
a. To continue to the next iteration of the loop
b. To exit the loop immediately
c. To skip the current iteration and move to the next one
d. To restart the loop from the beginning
Correct Answer: b
5. Which control statement is used to make a decision based on a condition?
a. for loop
b. switch statement
c. do-while loop
d. if-else statement
Correct Answer: d
6. In a switch statement, what happens if there is no break statement after a case?
a. The program exits
b. The next case is executed
c. The default case is executed
d. An error occurs
Correct Answer:b
7. Which control statement is used to handle exceptions or errors in a program?
a. try-catch statement
b. if-else statement
c. switch statement
d. do-while loop
Correct Answer: a
8. In a while loop, under what condition will the loop continue to execute?
a. When the condition is true
b. When the condition is false
c. When the loop reaches a certain number of iterations
d. When a specific key is pressed
Correct Answer: a
9. Which of the following is not a valid comparison operator in most programminglanguages?
a. ==
b. !=
c. <=
d. ><
Correct Answer: d
10. What does the continue statement do in a loop?
a. Exits the loop immediately
b. Skips the current iteration and continues with the next one
c. Restarts the loop from the beginning
d. Jumps to a specific label within the loop
Correct Answer: b
11. In C, how do you denote a multi-line comment?
a. // This is a comment
b. /* This is a comment */
c. # This is a comment
d. ' This is a comment
Correct Answer: b
12. In a for loop, which part is optional?
a. Initialization
b. Condition
c. Increment/Decrement
d. All parts are required
Correct Answer: a
12. How many times will the following loop execute?
cCopy code
for (int i = 0;
i < 5; i++)
{
// Loop body
}
a. 0 times
b. 1 time c.
4 times
d. 5 times
Correct Answer: d
13. In C, which control statement is used to handle multiple conditions and execute code blocks accordingly?
a. if statement
b. switch statement
c. for loop
d. while loop
Correct Answer: b
14. What does the default case in a switch statement do in C?
a. It is not a valid case label.
b. It specifies the default value for a variable.
c. It is executed when none of the other case labels match.
d. It indicates the end of the switch statement.
Correct Answer: c
15. Which operator is used to access the value stored in a pointer in C?
a. *
b. &
c. ->
d. $
Correct Answer: a
16. Which statement is used to declare a label in C?
a. declare
b. label
c. goto
d. case
Correct Answer: b
17. What is the purpose of the goto statement in C?
a. To create loops
b. To declare labels
c. To jump to a specific point in the code
d. To exit the program
Correct Answer: c
18. What happens if a return statement is encountered in a switch statement in C?
a. It exits the program.
b. It exits the current loop.
c. It exits the current switch statement.
d. It has no effect in a switch statement.
Correct Answer: c
19. Which statement is used to include the contents of another file in a C program?
a. #include
b. #define
c. #ifndef
d. #endif
Correct Answer: a
20. In C, which control statement is used for post-test loop execution?
a. for loop
b. while loop
c. do-while loop
d. switch statement
Correct Answer: c
21. What is the purpose of the do-while loop in C?
a. To execute code only once
b. To execute code repeatedly as long as a condition is true
c. To execute code repeatedly at least once, and then as long as a condition is true
d. To execute code for a specific number of times
Correct Answer: c
22. In C, what is the scope of a variable declared inside a for loop?
a. Global scope
b. Function scope
c. Block scope
d. No scope
Correct Answer: c
23. Which statement is used to define a function in C?
a. function
b. def
c. define
d. int
Correct Answer: d
24. What is the purpose of the switch statement in C?
a. To define functions
b. To execute code repeatedly
c. To make decisions based on multiple conditions
d. To declare variables
Correct Answer: c
25. In C, which of the following control structures can be used for indefinite loop execution?
a. if-else statement
b. for loop
c. do-while loop
d. switch statement
Correct Answer: c
26. Which statement is used to specify the default case in a switch statement in C?
a. default
b. case
c. else
d. break
Correct Answer: a
27. Which control statement is used to exit a loop prematurely in C?
a. exit
b. break
c. continue
d. return
Correct Answer: b
28. In C, what does the && operator represent?
a. Logical OR
b. Bitwise AND
c. Logical AND
d. Bitwise OR
Correct Answer: c
29. What is the output of the following code in C?
cCopy code
int x = 5;
if (x > 3 && x < 7)
{
printf("Hello");
}
else
{
printf("World");
}
a. Hello
b. World
c. Hello World
d. No output
Correct Answer: a
30. What is the purpose of the break statement in a switch statement in C?
a. To exit the program
b. To skip the current case and execute the next one
c. To exit the loop containing the switch statement
d. To restart the switch statement from the beginning
Correct Answer: b
31. In C, how is a while loop different from a do-while loop?
a. There is no difference; they are the same.
b. A while loop is for definite iteration, and a do-while loop is for indefinite iteration.
c. A while loop checks the condition after each iteration, while a do-while loop checks the condition before the first iteration.
d. A while loop can only be used inside a for loop.
Correct Answer: c
32. What is the output of the following code in C?
cCopy code
int i;
for (i = 0; i < 5; i++)
{
printf("%d ", i);
}
a. 0 1 2 3 4
b. 1 2 3 4 5
c. 0 1 2 3
d. 1 2 3 4
Correct Answer: a
33. In C, what is the purpose of the do-while loop?
a. To execute code only once
b. To execute code repeatedly as long as a condition is true
c. To execute code repeatedly at least once, and then as long as a condition is true
d. To execute code for a specific number of times
Correct Answer: c
34. What is the output of the following code in C?
cCopy code
int x = 5;
while (x > 0)
{
printf("%d ", x); x--;
}
a. 5 4 3 2 1
b. 1 2 3 4 5
c. 5 5 5 5 5
d. 0 1 2 3 4
Correct Answer: a
35. Which operator is used to access the address of a variable in C?
a. &
b. *
c. ->
d. @
Correct Answer: a
36. What is the purpose of the goto statement in C?
a. To create loops
b. To declare labels
c. To jump to a specific point in the code
d. To exit the program
Correct Answer: c
37. In C, what does the continue statement do?
a. Exits the program.
b. Exits the current loop or switch statement.
c. Skips the current iteration of a loop.
d. Jumps to a specific label in the code.
Correct Answer: c
38. Which statement is used to define a label in C?
a. declare
b. label
c. goto
d. case
Correct Answer: b
39. Which of the following is not a valid comparison operator in C?
a. ==
b. !=
c. ><
d. >=
Correct Answer: c
40. What is the output of the following code in C?
cCopy code
int i;
for (i = 0; i < 10; i++)
{
if (i % 2 == 0)
{
continue;
}
printf("%d ", i);
}
a. 0 1 2 3 4 5 6 7 8 9
b. 1 3 5 7 9
c. 0 2 4 6 8
d. 1 2 3 4 5 6 7 8 9
Correct Answer: b
41. In C, which statement is used to include the contents of another file?
a. #include
b. #define
c. #ifndef
d. #endif
Correct Answer: a
42. What is the purpose of the switch statement in C?
a. To define functions
b. To execute code repeatedly
c. To make decisions based on multiple conditions
d. To declare variables
Correct Answer: c
43. In C, which control structure can be used for indefinite loop execution?
a. if-else statement
b. for loop
c. do-while loop
d. switch statement
Correct Answer: c
44. Which control statement is used to exit a loop prematurely in C?
a. exit
b. break
c. continue
d. return
Correct Answer: b
45. In C, what does the || operator represent?
a. Logical AND
b. Bitwise OR
c. Logical OR
d. Bitwise AND
Correct Answer: c
46. In C, which control statement is used for pre-test loop execution?
a. for loop
b. while loop
c. do-while loop
d. switch statement
Correct Answer: a
47. What is the output of the following code in C?
cCopy code
int i = 5;
if (i++ == 6)
{ printf("Hello");
} else
{
printf("World");
}
a. Hello
b. World
c. Hello World
d. No output
Correct Answer: b
48. Which statement is used to exit a function and return a value in C?
a. exit()
b. break
c. continue
d. return
Correct Answer: d
49. What is the purpose of the default case in a switch statement in C?
a. It is not a valid case label.
b. It specifies the default value for a variable.
c. It is executed when none of the other case labels match.
d. It indicates the end of the switch statement.
Correct Answer: c
50. Which of the following is not a type of control statement in C?
a. if statement
b. switch statement
c. loop statement
d. variable declaration
Correct Answer: d
0 Comments