top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: In what case structure assignment should be avoided in code ?

+2 votes
457 views

Can I assign one structure variable of another structure variable of same structure type all the time ?

posted May 21, 2016 by Ganesh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

If structure has pointer or array member,it will lead to dangling pointer so we should avoid use of assignment operator in this case.here an attached image to illustarte how it will lead to dangling pointer problem.
enter image description here

Once you delete string (or free pointer) pointed by any pointer,because both pointer pointing to same string,string will be deleted so we will need to use deep copy.

answer May 21, 2016 by Shivam Kumar Pandey
...