C++ Language INTERVIEW QUESTION & ANSWERS
46. |
What is the use of default constructor? |
|
A constructors that accepts no parameters is called the default constructor.If no user-defined constructor exists for a class A and one is needed, the compiler implicitly declares a default parameterless constructor A::A(). This constructor is an inline public member of its class. The compiler will implicitly define A::A() when the compiler uses this constructor to create an object of type A. The constructor will have no constructor initializer and a null body. |
47. |
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.
|
48. |
What are class libraries? |
|
A class library is a set of reusable classes meant for providing a specific functionality (such as utility, networking, or user-interface related classes) that can be readily used by the application. |
49. |
What is a dangling pointer? |
|
A dangling pointer arises when we use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the dynamically allocated memory block after it is freed. |
50. |
What is the difference between shallow and deep copy? |
|
Shallow copy involves bit wise copy of the contents of one object into another object of the same type. A copy constructor and assignment operator provided by the compiler by default does shallow copy. Shallow copies create a problem when there are fields of pointer or reference type. In this case, the addresses are directly copied to another object and thus two different objects have fields pointing to the same objects. When one object is destroyed, the pointers/references in the other object become dangling pointers/references, which is dangerous.
Deep copy involves using the contents of one object to create an other instance of the same class. In a deep copy, the two objects may contain the same information but the target object will have its own buffers and resources. The destruction of one object will not affect the other object. Typically, we provide our own copy constructor and assignment operator implementations for doing deep copy of objects. |