Q 1. Which of the following is the correct way to define a pointer in C++?
A. int *ptr;
B. int ptr*;
C. pointer int *;
D. ptr int*;
Q 2. What does the 'new' operator do in C++?
A. Allocates memory for variables
B. Deallocates memory
C. Allocates memory dynamically for objects
D. Returns a reference to an object
Q 3. Which of the following will result in a compilation error in C++?
A. int x = 10;
B. int x = 'A';
C. int x = 10.5;
D. int x = 10.0;
Q 4. Which of the following is the correct syntax for declaring a constant in C++?
A. const int a = 10;
B. int const a = 10;
C. constant int a = 10;
D. both A and B
Q 5. In C++, which of the following is used to implement polymorphism?
A. Inheritance
B. Encapsulation
C. Abstraction
D. Function Overloading
Q 6. Which of the following is the correct definition of a class in C++?
A. class MyClass {}
B. class MyClass() {}
C. class MyClass; {}
D. class MyClass { }
Q 7. Which of the following is true about constructors in C++?
A. Constructor can have a return type.
B. Constructor is called only once.
C. Constructor cannot be inherited.
D. Constructor must have parameters.
Q 8. What is the default access specifier for members of a class in C++?
A. public
B. private
C. protected
D. none of the above
Q 9. Which of the following will be the output of the following C++ code? int a = 7, b = 3; cout << a % b;
A. 3
C. 7
D. Error
Q 10. What does the 'sizeof' operator do in C++?
A. Returns the size of the variable in bytes
B. Returns the size of the pointer
C. Returns the number of elements in an array
D. Allocates memory space for a variable
Q 11. Which of the following is used to release dynamically allocated memory in C++?
A. delete
B. free
C. malloc
D. release
Q 12. Which of the following C++ features allows you to access private members of a class from outside the class?
A. Friend function
B. Inheritance
C. Encapsulation
D. Polymorphism
Q 13. Which of the following statements about C++ destructors is correct?
A. A destructor is called explicitly by the programmer.
B. A destructor has the same name as the class but with a tilde (~) prefix.
C. A destructor can have parameters.
D. A destructor cannot be virtual.
Q 14. Which of the following is the correct way to define a function that accepts a pointer as an argument in C++?
A. void function(int *ptr);
B. void function(int ptr*);
C. void function(*int ptr);
D. void function(int& ptr);