Latest C++ Interview Questions and Answers Part-2
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 destuctors?
A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
A destructors as the name implies is used to destroy the objects that have been created by a constructors.
Like a constructor , the destructor is a member function whose name is the same as the class name but is precided by a tilde.
14. What is a class?
A class is a collection of objects.
15. what is the difference between c & c++?
C++ ia an object oriented programing but C is a procedure oriented programing.
C is super set of C++.
C can’t suport inheritance, function overloading, method overloading etc. but c++ can do this.
In c program the main function could not return a value but in the c++ the main function shuld return a value.
16. What are the few advantages of Inline function?
It offers an improved macro facility.
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?
An instance of a user-defined type is called an object. We can instantiate many objects from one class.
An object is an instance of a class