Function header for copy assignment operator

Copy assignment operator returns reference to object why?

1 Like

if you have worked with pointers in cpp, it should be pretty straightforward…
say int *ptr1 = new int;
int *ptr2 = new int;
*ptr1 = 10;
*ptr2 = 20;
ptr1 = ptr2;
here both pointers are pointing to same object having value 20, how?. since ptr1 and ptr2 represents addresses, ptr1 starts pointing to same address as ptr2.

similarly, when you write C= D, where C,D are objects… C,D actually represents addresses, so they are references… C and D are now pointing to same object.

thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

@sahazeer123 you have re-opened your doubt, can I help you with anything?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.