C++ Interview Questions and Answers

1 . What are the OOPS concepts ?

Answer : An object is an abstraction...

2. What are the advantages and disadvantages of using inline and const ?

Answers : Advantages of inline....

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) ?

Answer : In this method, we store all elements of second array in a hash table....

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 ?

Answer : #include<iostream>...

5. Which of the following concepts of OOPS means exposing only necessary information to client ?

A. Abstraction

B. Encapslution

C. Data Hiding

D. Data Binding

Answer : C. Data Hiding

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 ?

A. Privately

B. Publicly.

C. Protectedly

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++ ?

Answer : A virtual function will become pure virtual function...

10. Which of the following access specifiers is used in a class definition by default ?

A. Protected

B. Public

C. Private

D. Friends

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 ?

A. Abstraction

B. Encapsulation

C. Inhertiance

D. None

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.

A. Dynamic

B. Runtime

C. Early binding

D. Static

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

Answer : B. Ad-hoc polymorphism

19. Find Largest number from set of given numbers ?

Answer : Find number of digits in the largest number. Let us assume number of digits be n...

20. What is the best way to sort an array of 0s and 1s ?

Answer : Sort an array elements means arrange...

21. Finding all substrings of a given number that are divisible by 11.

Answer : Query(l, r) : find if the sub-string between the indices l and r....

22. Dangling Pointer ?

Answer : A dangling pointer is pointing to a memory location...

23. What is Inheritance with example in C++ ?

Answer : Inheritance is one of the key features of Object-oriented programming...

24. Structure in C++ ?

Answer : Structure is a collection of variables of different data types...

25. Print Pyramid Triangle in C++ ?

Answer : To print pyramid triangle in C++, we have use two for loop...

Related Searches to C++ Interview Questions and Answers