top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

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

+2 votes

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 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
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.