Loading...

C++ Programming Interview Questions

This article is mainly focused on the most repeatedly asked and the latest updated questions.

C++ Interview Questions Set-2

Commonly Asked C++ Programming Interview Questions | Set 2


11. Define Encapsulation in C++?
Ans: Encapsulation is the process of binding together the data and functions in a class. It is applied to prevent direct access to the data for security reasons. The functions of a class are applied for this purpose. For example, the customers' net banking facility allows only the authorized person with the required login id and password to get access. That is too only for his/her part of the information in the bank data source.


12. What is an abstraction in C++?
Ans: An abstraction in C++ is hiding the internal implementations and displaying only the required details. For example, when you send an important message through email, at that time, only writing and clicking the send option is used. This outcome is just the success message that is displayed to confirm that your email has been sent. However, the process followed in transferring the data through email is not displayed because it is of no use to you.


13. Briefly explain the concept of Inheritance in C++.
Ans: C++ allows classes to inherit some of the commonly used state and behavior from other classes. This process is known as inheritance.


14. Define access specifier and its various types in C++.
Ans: An access specifier offers how it is possible to define how the class members, i.e., functions and variables, will be accessed outside the class's scope. There are three types of access specifier in C++:

  • Public: Class members declared as public can be accessed throughout the program (code).
  • Private: Such class members can’t be accessed outside the class in which they are declared and are only accessible within the same class. Even child classes are disabled to access private members of its parent class.
  • Protected: In addition to the class in which they are declared, the child classes can access its parent class's protected members.


15. What is operator overloading in C++?
Ans: An overloaded declaration is a declaration in the same scope of function or operator declared with the same name more than once.


16. What is this pointer?
Ans: The ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. ‘this’ pointer is a constant pointer that holds the memory address of the current object. ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with class name).


17. What are the advantages of C++?
Ans:

  • C++ is a highly portable language, i.e. the software developed using C++ language can run on any platform
  • C++ is a partial object-oriented programming language and hence includes concepts such as classes, objects, inheritance, polymorphism, abstraction, data hiding
  • C++ contains a rich function library
  • C++ is a powerful, efficient and fast language and hence is the popular language for competitive coding.


18. Why is C++ called a partial object-oriented programming language?
Ans: C++ can be called as a partial object-oriented language due to the following reasons:

  • For any language to be completely object-oriented, no method should exist without an object. But in case of C++, we can write a valid C++ program without usage of a class or objects as the main() function need not be part of any class.
  • In C++, globally declared variables can be accessed from anywhere and this violates the law of encapsulation (data protection).
  • Also, C++ violates the law of inheritance with its principle of multiple-Inheritance.


19. What is pointer in C++?
Ans: Pointers in C++ are a data type that store the memory address of another variable.


20. Define a class template?
Ans: A class template is a name given to the generic class. The use of the keyword template is made for defining a class template.


- Related Topics