title: Memcpy and Memset on structures of Short Type in C
body: <p>I have a query about using memset and memcopy on structures and their reliablity. For eg:</p>
  
  <p>I have a code looks like this</p>
  
  <pre><code>typedef struct
      {
      short a[10];
      short b[10];
  }tDataStruct;
  
   tDataStruct m,n;
  
  memset(&amp;m, 2, sizeof(m));
  memcpy(&amp;n,&amp;m,sizeof(m));
  </code></pre>
  
  <p>My question is,</p>
  
  <p>1): in memset if i set to 0 it is fine. But when setting 2 i get m.a and m.b as 514 instead of 2. When I make them as char instead of short it is fine. Does it mean we cannot use memset for any initialization other than 0? Is it a limitation on short for eg</p>
  
  <p>2): Is it reliable to do memcopy between two structures above of type short. I have a huge
      strings of a,b,c,d,e... I need to make sure copy is perfect one to one.</p>
  
  <p>3): Am I better off using memset and memcopy on individual arrays rather than collecting in a structure as above?</p>
  
  <p>One more query,</p>
  
  <p>In the structue above i have array of variables. But if I am passed pointer to these arrays
  and I want to collect these pointers in a structure</p>
  
  <pre><code>typedef struct
      {
      short *pa[10];
      short *pb[10];
  }tDataStruct;
  
   tDataStruct m,n;
  
  memset(&amp;m, 2, sizeof(m));
  memcpy(&amp;n,&amp;m,sizeof(m));
  </code></pre>
  
  <p>In this case if i or  memset of memcopy it only changes the address rather than value. How do i change the values instead? Is the prototype wrong?</p>
  
  <p>Please suggest. Your inputs are very imp</p>
  
  <p>Thanks
  dsp guy</p>