memcpy structure variables
<p>It might sound a very basic question but I have following structure in C++:</p>

<pre><code>struct SMessage
{
    unsigned int id; 
    unsigned int payloadSize; 
    unsigned char data[100];  
    unsigned char *data2; 
}; 
</code></pre>

<p>lets say I have two variables of SMessage type (msg1,msg2) and i want to memcpy individual members of msg1 into msg2 (please dont ask why!). I understand that copying id and payLoadSize are relatively straight forward:</p>

<pre><code>memcpy(&amp;msg2.id, &amp;msg1.id, sizeof(unsigned int)); 
memcpy(&amp;msg2.payLoadSize, &amp;msg2.payLoadSize, sizeof(unsigned int));
</code></pre>

<p>but for copying the data[] should we do:</p>

<pre><code>memcpy(&amp;msg2.data, &amp;msg1.data, 100*sizeof(unsigned char)); 
</code></pre>

<p>or</p>

<pre><code>memcpy(msg2.data, msg2.data, 100*sizeof(unsigned int)) 
</code></pre>

<p>would also work because data is an array object?</p>

<p>How will we copy the struct member data2 which is declared as a pointer instead? </p>