title: Hello people, I get an segmentation fault on the program below and I can't figure it out
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;pthread.h&gt;
  
  int p=2; //nr de thread-uri
  int **a, **c;
  int n=4;
  void *Matrix_Add(void *);
  
  
  int main(){
  
  int i, j, q;
  int *params;                                
  pthread_t *ids;                             
  
  a=(int**)malloc(sizeof(int*)*n);            
  c=(int**)malloc(sizeof(int*)*n);
    for(i=0; i&lt;n; i++){
        a[i]=(int*)malloc(sizeof(int)*n);
        c[i]=(int*)malloc(sizeof(int));
      }
  params=(int*)malloc(sizeof(int)*p);             
  ids=(pthread_t*)malloc(sizeof(pthread_t)*p);    
  
    for(i=0; i&lt;n; i++){                       
      for(j=0; j&lt;n; j++){
          a[i][j]=1;
          }
          }
    for(i=0; i&lt;n; i++){
          for(j=0; j&lt;n; j++)
              printf("%d ", a[i][j]);
              printf("\n");
          }
  
    for(q=0; q&lt;p; q++){
      params[q]=q;
      pthread_create(&amp;ids[q], 0, Matrix_Add, (void*)params[q]);
  }
  for(q=0; q&lt;p; q++){
      pthread_join(ids[q], 0);
  }
  
  
  
  
  return 0;
  
  
  }
  
  void *Matrix_Add(void *params){
  
  int i, j, first, last;
  int q=*(int*)params;
  int s=n/p;
  first=q*s;
  last=first+s;
  
  for(i=first; i&lt;last; i++){
      c[i]=0;
      for(j=0; j&lt;n; j++){
          c[i]+=a[i][j];
      }
  }
  return 0;
  }
  </code></pre>
  
  <p>The program should create 2 threads, divide the 2d array's rows 2 by 2 (2 rows for each thread), and calculate the sum of each row of matrix a and write it in matrix c. Matrix c should have n lines and 1 column. </p>