C++ MCQ Quiz
1. What is the difference between a compiler and an interpreter?
a) A compiler translates the entire program into machine code, while an interpreter translates it line by line.
b) A compiler translates the program line by line, while an interpreter translates the entire program into machine code.
c) A compiler and an interpreter are the same thing.
d) A compiler translates the program into assembly language, while an interpreter translates it into machine code.
e) A compiler translates the program into machine code, while an interpreter translates it into assembly language.
2. Which of the following is not a data type in C?
a) char
b) int
c) float
d) double
e) string
3. What is the purpose of a pointer in C?
a) To store the address of a variable.
b) To store the value of a variable.
c) To store the size of a variable.
d) To store the data type of a variable.
e) To store the name of a variable.
4. Which of the following is not a control structure in C?
a) if-else
b) for
c) while
d) switch
e) do-while
5. What is the output of the following code snippet?
```
int x = 5;
printf("%d\n", ++x);
```
a) 4
b) 5
c) 6
d) 10
e) None of the above
6. Which of the following is not a logical operator in C?
a) &&
b) ||
c) !
d) &
e) |
7. What is the purpose of the 'break' statement in C?
a) To terminate a loop or switch statement.
b) To skip the current iteration of a loop.
c) To execute the next iteration of a loop.
d) To return a value from a function.
e) To declare a variable.
8. What is the difference between '==' and '=' in C?
a) '==' is used for assignment, while '=' is used for comparison.
b) '==' is used for comparison, while '=' is used for assignment.
c) '==' and '=' are interchangeable.
d) '==' is used for addition, while '=' is used for subtraction.
e) '==' is used for multiplication, while '=' is used for division.
9. What is the output of the following code snippet?
```
int x = 10, y = 5;
if (x > y) {
printf("%d\n", x);
} else {
printf("%d\n", y);
}
```
a) 5
b) 10
c) 15
d) 0
e) None of the above
10. What is the purpose of the 'continue' statement in C?
a) To terminate a loop or switch statement.
b) To skip the current iteration of a loop.
c) To execute the next iteration of a loop.
d) To return a value from a function.
e) To declare a variable.
11. What is the output of the following code snippet?
```
int x = 5, y = 10;
printf("%d\n", x + y);
```
a) 5
b) 10
c) 15
d) 50
e) None of the above
12. What is the purpose of the 'sizeof' operator in C?
a) To return the value of a variable.
b) To return the size of a variable.
c) To return the data type of a variable.
d) To return the name of a variable.
e) To return the address of a variable.
13. What is the output of the following code snippet?
```
int x = 5, y = 10;
if (x > y) {
printf("%d\n", x);
} else if (y > x) {
printf("%d\n", y);
} else {
printf("Equal\n");
}
```
a) 5
b) 10
c) Equal
d) 15
e) None of the above
14. What is the purpose of the 'do-while' loop in C?
a) To execute a block of code while a condition is true.
b) To execute a block of code at least once, even if the condition is false.
c) To execute a block of code until a condition is true.
d) To execute a block of code a specific number of times.
e) To execute a block of code based on a switch statement.
15. What is the output of the following code snippet?
```
int x = 5, y = 10;
printf("%d\n", x * y);
```
a) 5
b) 10
c) 15
d) 50
e) None of the above
16. What is the purpose of the 'else' statement in C?
a) To execute a block of code if a condition is true.
b) To execute a block of code if a condition is false.
c) To execute a block of code based on a switch statement.
d) To execute a block of code a specific number of times.
e) To execute a block of code until a condition is true.
17. What is the output of the following code snippet?
```
int x = 5;
printf("%d\n", x++);
```
a) 4
b) 5
c) 6
d) 10
e) None of the above
18. What is the purpose of the 'switch' statement in C?
a) To execute a block of code if a condition is true.
b) To execute a block of code if a condition is false.
c) To execute a block of code based on a specific value.
d) To execute a block of code a specific number of times.
e) To execute a block of code until a condition is true.
19. What is the output of the following code snippet?
```
int x = 5, y = 10;
if (x > y) {
printf("%d\n", x);
} else if (y > x) {
printf("%d\n", y);
}
```
a) 5
b) 10
c) 15
d) 0
e) None of the above
20. What is the purpose of the 'for' loop in C?
a) To execute a block of code while a condition is true.
b) To execute a block of code at least once, even if the condition is false.
c) To execute a block of code until a condition is true.
d) To execute a block of code a specific number of times.
e) To execute a block of code based on a switch statement.