C++ Interview Question and Answers
81. |
What are shallow and deep copies? |
|
A shallow copy is used to copy actual values of the data. It means, if the pointer points to dynamically allocated memory, the new object’s pointer in the copy still points to items inside the old objects and the returned object will be left pointing to items that are no longer in scope.
A copy of the dynamically allocated objects is created with the help of deep copy. This is done with the help of an assignment operator, which needs to be overloaded by the copy constructor. |
|
|
82. |
How can you return the current involving object from its member function? |
|
return(*this);
|
|
|
83. |
What is the difference between prefix and postfix versions of operator++()? |
|
- The prefix and postfix versions of operator ++() can be differentiated on the basis of arguments defined.
-
The postfix operator ++() consists of a dummy parameter of int datatype; whereas, a dummy parameter is not found in the prefix operator ++().
|
|
|
84. |
Can a static member function access member variable of an object? |
|
No, because to access the member variable of an object inside its member function, this pointer is required. Since static functions are class functions, this pointer will not be passed as its arguments. |
|
|
85. |
What is the advantages of using the Inline function? |
|
- An inline keyword before a function suggests the compiler to insert the complete body of the function wherever that function is invoked.
- Inline expansion is typically used to eliminate the inherent cost involved in calling a function.
-
It is typically used for functions that need quick execution.
|
|
|