title: array used uninitialized in this function
body: <p>My task is to allocate memory for an array of integers (n elements), to give random values to each one of them and to print them sorted and unsorted. When I compile the code, I get this warning "'v' is used uninitialized in this function", and when I try to run it, I get "Segmentation fault". </p>
  
  <p>I was wondering why am I supposed to initialize the array if I want to fill it up with random values? Is there a problem in the way I allocate memory for the array?(I'm not sure about the cast i did)</p>
  
  <p>This is the source code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      int i, j, max, n, *v, aux;
  
      scanf("%d%d", &amp;n, &amp;max);
  
      *v=(int*)malloc(n*sizeof(int));
      for(i=0; i&lt;n; i++){
          srand(time(NULL));
          v[i]=rand()%max;
      }
  
      for(i=0; i&lt;n; i++){
          printf("%d ", v[i]);
      }
      printf("\n");
  
      for(i=0; i&lt;n-1; i++){
          for(j=0; j&lt;n-i-1; j++){
              if(v[j]&gt;v[j+1]){
                  aux=v[j];
                  v[j]=v[j+1];
                  v[j+1]=aux;
              }
          }
      }
      for(i=0; i&lt;n; i++){
          printf("%d ", v[i]);
      }
      printf("\n");
  
      return 0;
  }
  </code></pre>
  
  <p>I would be grateful if someone could make me understand what I do wrong, and eventually modify part of the source.</p>