0% found this document useful (0 votes)
24 views

GP OOPS C++ This Pointer Interview

The document discusses the this pointer and differences between shallow and deep copying. The this pointer refers to the object that called the member function and is necessary when a local variable and data member have the same name. Both shallow and deep copying are used to copy data between objects, but shallow copying only stores references to the original objects while deep copying recursively stores copies of the objects themselves.

Uploaded by

arnesh dadhich
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

GP OOPS C++ This Pointer Interview

The document discusses the this pointer and differences between shallow and deep copying. The this pointer refers to the object that called the member function and is necessary when a local variable and data member have the same name. Both shallow and deep copying are used to copy data between objects, but shallow copying only stores references to the original objects while deep copying recursively stores copies of the objects themselves.

Uploaded by

arnesh dadhich
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Interview Questions

1. What is this pointer?


this pointer is accessible only inside the member functions of a class and points
to the object which has called this member function.
2. When is it necessary to use this pointer?
Suppose we have two local variables with the same name as the data members’
names. Suppose you want to assign the local variable value to the data
members. In that case, you won’t be able to do until unless you use this pointer
because the compiler won’t know that you are referring to the object’s data
members unless you use this pointer.

3. What is similar between deep copy and shallow copy?


Both are used to copy data between objects.

4. What is the difference between deep copy and shallow copy?

Shallow Copy Deep Copy

Shallow Copy stores the references of Deep copy stores copies of the
objects to the original memory object’s value.
address.

Shallow Copy reflects changes made Deep copy doesn’t reflect changes
to the new/copied object in the made to the new/copied object in the
original object. original object.

Shallow Copy stores the copy of the Deep copy stores the copy of the
original object and points the original object and recursively copies
references to the objects. the objects as well.

Shallow copy is faster. Deep copy is comparatively slower.

You might also like