C++ Interview Questions and Answers
1 . What are the OOPS concepts ?
2. What are the advantages and disadvantages of using inline and const ?
3. Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ?
4. Write a function that takes an integer array as an input and find the largest number in the array. You can not sort array or use any API or searching needs ?
5. Which of the following concepts of OOPS means exposing only necessary information to client ?
C. Data Hiding
D. Data Binding
6. Encapsulation is ?
A. Binding code and data together
B. Using single interface for general class of actions.
C. Reduce Complexity
D. All the above
Answer : C. Reduce Complexity
7. In c++ how are protected members of a base class accessed in derived class when inherited privately ?
D. Not Inherited
Answer : A. Privately
8. State whether the following statements about inheritance are True or False.
I. A public member of a class can be accessed by its own objects using the dot operator.
II. While inheriting, the private members of the base class will never become the members of its derived class.
A. True, False
B. False, True
C. True, True
D. False, False
Answer : C. True, True
9. What is pure virtual function in C++ ?
10. Which of the following access specifiers is used in a class definition by default ?
Answer : C. Private
11. Which of the following can access private data members or member functions of a class ?
A. Any function in the program.
B. All global functions in the program.
C. Any member function of that class.
D. Only public member functions of that class.
Answer : C. Any member function of that class.
12. Which of the following concepts means wrapping up of data and functions together ?
Answer : B. Encapsulation
13. Which of the following statements about virtual base classes is correct ?
A. It is used to provide multiple inheritance
B. It is used to avoid multiple copies of base class in derived class
C. It is used to allow multiple copies of base class in a derived class
D. It allows private members of the base class to be inherited in the derived class
Answer : B. It is used to avoid multiple copies of base class in derived class.
14. A virtual function that has no definition within the base class is called ?
A. Pure virtual function
B. Pure static function
C. Pure Const function
D. Virtual Function
Answer : A. Pure virtual function
15. C++ supports run time polymorphism with the help of virtual functions, which is called ______ binding.
C. Early binding
Answer : A. Dynamic
16. Find the wrong statement about Abstract Class ?
A. We can’t create its objects
B. We can’t create pointers to an abstract
C. It contains at least one pure virtual function
D. We can create references to an abstract class
Answer : B. We can’t create pointers to an abstract class
17. Syntax for Pure Virtual Function is ?
A. virtual void show()==0
B. void virtual show()==0
C. virtual void show()=0
D. void virtual show()=0
Answer : D. void virtual show()=0
18. The operator when overloaded in a class ?
A. Virtual polymorphism
B. Ad-hoc polymorphism
C. Transient polymorphism
D. Pseudo polymorphism