C++ Programming - Mock Interview Test
1. What is the correct syntax to declare a pointer in C++?
A. int *ptr;
B. ptr int*;
C. int ptr*;
D. pointer int*;
2. Which operator is used to allocate memory dynamically in C++?
a) malloc
b) new
c) calloc
d) allocate
3. What is the default access modifier for members of a class in C++?
a) private
b) protected
c) public
d) default
4. Which function is used to deallocate memory in C++?
a) dealloc
b) free
c) delete
d) delete[]
5. Which of the following is the correct way to create a constructor in C++?
a) class MyClass()
b) MyClass() {}
c) void MyClass() {}
d) constructor MyClass() {}
6. In C++, which of the following is used to define a constant?
a) static
b) final
c) const
d) define
7. What does the this pointer in C++ represent?
a) Pointer to the current object
b) Pointer to the base class
c) Pointer to the parent class
d) Pointer to a global variable
8. Which operator is used to access members of a class in C++?
A. ::
B. .
C. ->
D. *
9. What is the correct way to inherit a class in C++?
A. class Child : parent {}
B. class Child < parent {}
C. class Child : public parent {}
D. class Child = parent {}
10. Which of the following is true for virtual functions in C++?
A. They cannot be overridden
B. They are called by object pointers or references
C. They must be static
D. They do not support dynamic polymorphism
11. What is the output of the following code snippet?
int x = 10;
cout << ++x;
A. 10
B. 11
C. Error
D. 0
12. What is the purpose of the friend keyword in C++?
A. It allows access to private and protected members of a class
B. It defines a function that can only be accessed within the class
C. It limits the access to the base class
D. It defines an alias for a function
13. Which function is used to find the length of a string in C++?
A. length()
B. strlength()
C. size()
D. strlen()
14. What will be the output of the following code?
int x = 5;
int y = 10;
cout << x + y;
A. 5
B. 10
C. 15
D. Error
15. What is the purpose of #include in C++?
A. It declares a function
B. It imports a library or header file
C. It defines a constant
D. It starts a function
16. Which of the following is a characteristic of a static member in C++?
A. It is shared by all objects of the class
B. It can only be accessed through the class name
C. It must be initialized in a constructor
D. All of the above
17. Which of the following is the correct way to declare an array of 10 integers in C++?
A. int arr(10);
B. int arr[10];
C. array
arr(10);
D. arr[] = {1, 2, 3};
18. In C++, which keyword is used to handle exceptions?
A. throw
B. catch
C. try
D. All of the above
19. Which of the following will give an error in C++?
A. int x = 10;
B. int x; x = 10;
C. int x = 10; x = "Hello";
D. int x = 10; x = 20;
20. Which of the following data types in C++ has the highest storage size?
A. char
B. int
C. float
D. double
Submit
Go Back