title: Concatenating 2 arrays in C
body: <p>I'm trying to create a function that concatenates 2 arrays and then returns the sum array back.
  I've been using the following code:</p>
  
  <pre><code>    #include "stdio.h";
  
  struct array {
      int length;
      int *array;
  };
  
  struct array add(struct array a, struct array b) {
      int length = a.length + b.length;
      int sum[length];
      for (int i = 0; i &lt; length; ++i) {
          if (i &lt; a.length) {
              sum[i] = a.array[i];
          } else {
              sum[i] = b.array[i - a.length];
          }
      }
  
      struct array c;
      c.length = length;
      c.array = sum;
      return c;
  }
  
  int main() {
      int a[] = {1, 2, 3};
      struct array s1;
      s1.array = a;
      s1.length = sizeof(a) / sizeof(a[0]);
  
      int b[] = {4, 5, 6};
      struct array s2;
      s2.array = b;
      s2.length = sizeof(b) / sizeof(b[0]);
  
      struct array sum = add(s1, s2);
      for (int i = 0; i &lt; sum.length; ++i) {
          printf("%d\n", sum.array[i]);
      }
      return 0;
  }
  </code></pre>
  
  <p>The output is:
  1,
  17,
  6356568,
  1959414740,
  1,
  1959661600</p>
  
  <p>What am I doing wrong?</p>