title: Copying structure members
body: <p>I am more confused with structures. There are many ways to copy a structure.</p>
  
  <pre><code>struct complex
  {
     int real;
     int imaginary;
  };
  
  Assume c1 is complex structure variable. c2 is pointer of complex type.
  </code></pre>
  
  <p>One way is simply assign one structure to another. <code>c1=*c2</code>. 
  I tried it. It works fine. But c2 will give the address of first element of structure complex. Then how the entire structure will be copied? Am i more confused with pointers?</p>
  
  <p>Another way is using <code>memcpy</code>  <code>memcpy(&amp;c1,c2,sizeof(struct complex))</code>. </p>
  
  <p>My doubt is on member-wise structure copying.
        <code>memcpy(&amp;c1.real, &amp;c2-&gt;real, sizeof(struct complex))</code></p>
  
  <p>I read that the above method is not safe. Because it won't work if we change the order of structure members. Nobody explained how is not safe? It confuses me because both variables are same structures , i am specifying what i want to copy [real in this case]. Then why is it not safe? could anybody please explain it?</p>