C++ Common Questions
C++ Common Questions
A. int
B. float
C. char
D. string
Answer: D
14. What is the correct way to read input from the user in C++?
A. cin << x;
B. cin >> x;
C. x << cin;
D. x >> cin;
Answer: B
17. What is the correct way to include a standard library header file in C++?
A. include <iostream>
B. include "iostream"
C. import <iostream>
D. import "iostream"
Answer: A
18. What is the output of the following code snippet?
```
int x = 10;
int y = 5;
int result = x % y;
cout << result;
```
A. 0
B. 1
C. 2
D. Compilation error
Answer: A
19. Which keyword is used to define a class that inherits from another class in C++?
A. extend
B. inherits
C. derive
D. :
Answer: D
22. Which keyword is used to define a class member that is accessible without creating an
instance of the class?
A. static
B. const
C. final
D. public
Answer: A
23. What is the output of the following code snippet?
```
int x = 5;
int y = 2;
int result = x / y;
cout << result;
```
A. 2
B. 2.5
C. 3
D. Compilation error
Answer: C
statement
B. To continue to the next iteration of a loop
C. To return a value from a function
D. To throw an exception
Answer: B
26. Which keyword is used to define a class member that cannot be changed once assigned a
value?
A. const
B. static
C. final
D. private
Answer: A
27. What is the output of the following code snippet?
```
int x = 10;
int y = 5;
int result = x + y * 2;
cout << result;
```
A. 20
B. 25
C. 30
D. Compilation error
Answer: C
33. Which keyword is used to define a variable that can hold the memory address of another
variable in C++?
A. address
B. reference
C. pointer
D. memory
Answer: C
39. Which keyword is used to define a class member that can be accessed from any class?
A. public
B. private
C. protected
D. static
Answer: A
42. Which
48. Which keyword is used to define a variable that cannot be changed once assigned a value?
A. const
B. static
C. final
D. private
Answer: A