title: Assign to array in struct in c
body: <p>I have the following code:</p>
  
  <pre><code>typedef struct Test {
    long mem[1000];
  } Test;
  
  extern Test *test;
  int main() {
      Test *test =  (Test *)malloc(sizeof(Test)); 
      test-&gt;mem[0] = 1;
      test-&gt;mem[1] = 2;
      test-&gt;mem[2] = 3;
      test-&gt;mem[3] = 4;
      test-&gt;mem[4] = 5;
      test-&gt;mem[5] = 6;
     return 0;
  }
  </code></pre>
  
  <p>It's working OK, but I want to change the initalization of the mem array to be in that way:</p>
  
  <pre><code>test-&gt;mem = {1,2,3,4,5,6};
  </code></pre>
  
  <p>But the gcc giving me this error:</p>
  
  <blockquote>
    <p>error: expected expression before '{' token   test->mem = {1,2,3,4,5,6};
    With arrow pointing to the left open braces.</p>
  </blockquote>
  
  <p>What it can be?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong>
  I also try this code:</p>
  
  <pre><code>long mem[1000] = {1,2,3,4,5,6};
      test-&gt;mem = mem;
  </code></pre>
  
  <p>And I'm getting this error from gcc:</p>
  
  <blockquote>
    <p>error: incompatible types when assigning to type 'long int[1048576]'
    from type 'long int *'  test->mem = mem;</p>
  </blockquote>
  
  <p>I'm not allow to use any C functions.</p>