Interview Questions C++

C++


11. Define Constructors?
A constructor is a member function with the same name as its class. The constructor is invoked whenever an object of its associated class is created.It is called constructor because it constructs the values of data members of the class.

12. How variable declaration in C++ differs that in C?
C requires all the variables to be declared at the beginning of a scope but in C++ we can declare variables anywhere in the scope. This makes the programmer easier to understand because the variables are declared in the context of their use

13. Define destructors?
a. A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
b. A destructors as the name implies is used to destroy the objects that have been created by a constructors.
c. Like a constructor, the destructor is a member function whose name is the same as the class name but is preceded by a tilde.

14. What is a class?
A class is a collection of objects.

15. What is the difference between C & C++?
C++ is an object oriented programing but C is a procedure oriented programing.
a. C is super set of C++.
b. C can't support inheritance, function overloading, method overloading etc. but c++ can do this.
c. In c program the main function could not return a value but in the c++ the main function should return a value.

16. What are the few advantages of Inline function?
a. It offers an improved macro facility.
b. By using the inline functions, the user can split a large function with many nested modules of statement blocks into many small inline functions.

17. What is copy constructor?
Copy constructor is a constructor function with the same name as the class and used to make deep copy of objects.

18. What is default constructor?
A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.

19. What is a scope resolution operator?
The scope resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.

20. What is the difference between Object and Instance?
a. An instance of a user-defined type is called an object. We can instantiate many objects from one class.
b. An object is an instance of a class.