title: Assigning values to an array after malloc causes crash
body: <p>I got a little assignment to do with C, but I can't seam to fill up an array that I allocated memory to. The code is like so..</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  int main(){
      int *x, *y, n, m, i;
  
      printf("Enter lenght of arrays x and y (separated by space): ");
      scanf("%d%d", &amp;n, &amp;m); fflush(stdin);
  
      if (x = (int*)malloc(sizeof(int) * n) == NULL){
          fprintf(stderr, "Error!\n");
          exit(1);
      }
      if (y = (int*)malloc(sizeof(int) * m) == NULL){
          fprintf(stderr, "Error!\n");
          exit(1);
      }
  
      printf("Enter %d values for X array (separated by space) ", n);
      for (i = 0; i &lt; n; i++)
          scanf("%d", x + i);
      fflush(stdin);
  
      printf("Enter %d values for Y array (separated by space): ", m);
      for (i = 0; i &lt; m; i++)
          scanf("%d", y + i);
      } //the two for's were originally in a function, I tried using the code like this as well
      return 0;
  }
  </code></pre>
  
  <p>I also tried running scanf("%d", x[i]); but nothing works. Every time I hit Enter after typing in the array for X the program crashes. By the way, originally no fflush(stdin) was there originally, I added them because I thought that the input took \0 as one of the values and that created errors.</p>
  
  <p>Thank you for reading! :)</p>