title: Dealing with error - expected expression before struct in C
body: <p>I'm trying to implement a dynamic array with code suggested on this thread <a href="https://stackoverflow.com/questions/3536153/c-dynamically-growing-array">C dynamically growing array</a> .  I want to return a struct Array from a function, but I get an error on the first line of <code>foo()</code> (error expected expression before 'struct').  I've seen many other examples of this, but the solutions don't seem to apply.  My apologies if one of them does.  Here is my full code:</p>
  
  <pre><code>typedef struct {
    int *array;
    size_t used;
    size_t size;
  } Array;
  
  void initArray(Array *a, size_t initialSize) {
    a-&gt;array = (int *)malloc(initialSize * sizeof(int));
    a-&gt;used = 0;
    a-&gt;size = initialSize;
  }
  
  void insertArray(Array *a, int element) {
    // a-&gt;used is the number of used entries, because a-&gt;array[a-&gt;used++] 
  //updates a-&gt;used only *after* the array has been accessed.
    // Therefore a-&gt;used can go up to a-&gt;size
    if (a-&gt;used == a-&gt;size) {
      a-&gt;size *= 2;
      a-&gt;array = (int *)realloc(a-&gt;array, a-&gt;size * sizeof(int));
    }
    a-&gt;array[a-&gt;used++] = element;
  }
  
  void freeArray(Array *a) {
    free(a-&gt;array);
    a-&gt;array = NULL;
    a-&gt;used = a-&gt;size = 0;
  }
  
  struct Array foo ()
  {
      Array a;
      int i;
      initArray(&amp;a, 5);  // initially 5 elements
      for (i = 0; i &lt; 100; i++)
        insertArray(&amp;a, i);  // automatically resizes as necessary
      printf("%d\n", a.array[9]);  // print 10th element
      printf("%d\n", a.used);  // print number of elements
      freeArray(&amp;a);
      return struct Array a;
  }
  </code></pre>