C++ Important Notes Click Here
C++ MCQ Quiz (20+20=40 Qu.)
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
$ads={1}
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
$ads={2}
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.
C++ MCQ Next 20 Qu.
1. Which of the following is not a valid C data type?
a) float
b) double
c) string
d) char
2. What is the output of the following code snippet?
int x = 5;
printf("%d", ++x);
a) 5
b) 6
c) 4
d) Error
3. Which of the following is a loop statement in C?
a) if
b) for
c) switch
d) break
4. What is the output of the following code snippet?
int x = 10;
if(x > 5 && x < 15)
printf("True");
else
printf("False");
a) True
b) False
c) Error
d) None of the above
5. What is the purpose of the 'sizeof' operator in C?
a) To return the size of a variable
b) To return the address of a variable
c) To return the value of a variable
d) To return the type of a variable
6. What is the output of the following code snippet?
int x = 5, y = 10;
printf("%d", x+y);
a) 510
b) 15
c) Error
d) None of the above
7. Which of the following is not a valid C keyword?
a) int
b) double
c) char
d) var
8. What is the output of the following code snippet?
int x = 5, y = 10;
printf("%d", x*y);
a) 15
b) 50
c) Error
d) None of the above
9. Which of the following is a valid way to declare an array in C?
a) int arr[5] = {1, 2, 3, 4, 5};
b) int arr[] = {1, 2, 3, 4, 5};
c) int arr[5];
d) All of the above
10. What is the output of the following code snippet?
int x = 5;
printf("%f", x);
a) 5.000000
b) 5
c) Error
d) None of the above
11. Which of the following is not a valid C operator?
a) +
b) ++
c) **
d) /
12. What is the output of the following code snippet?
int x = 5;
printf("%d", x++);
a) 5
b) 6
c) Error
d) None of the above
13. What is the purpose of the 'break' statement in C?
a) To exit a loop or switch statement
b) To continue to the next iteration of a loop
c) To print a value to the console
d) None of the above
14. Which of the following is not a valid way to declare a function in C?
a) void myFunction();
b) int myFunction(int x);
c) myFunction(int x);
d) All of the above are valid
15. What is the output of the following code snippet?
int x = 5, y = 10;
if(x > y)
printf("True");
else
printf("False");
a) True
b) False
c) Error
d) None of the above
16. Which of the following is not a valid C library?
a) stdio.h
b) math.h
c) string.h
d) console.h
17. What is the output of the following code snippet?
int x = 5;
printf("%d", x == 5 ? 1 : 0);
a) 1
b) 0
c) Error
d) None of the above
18. What is the purpose of the 'return' statement in C?
a) To exit a function and return a value
b) To print a value to the console
c) To declare a variable
d) None of the above
19. What is the output of the following code snippet?
int x = 5;
printf("%d", x > 3 && x < 10 ? 1 : 0);
a) 1
b) 0
c) Error
d) None of the above
20. Which of the following is not a valid C control structure?
a) if-else
b) for
c) switch
d) do-while
C++ Object Oriented Programming PDF Notes Download