title: Calculate the sum of two numbers using thread
body: <p>I have this little program I wrote to read two numbers from a user and calculate their sum using a thread function, which is also responsible for displaying the result on the screen.</p>
  
  <pre><code>int global[2];
  
  void *sum_thread(void *arg)
  {
      int *args_array;
      args_array = *(int**)arg;
  
      int n1,n2,sum;
      n1=args_array[0];
      n2=args_array[1];
      sum = n1+n2;
  
      printf("N1 + N2 = %d\n",sum);
  
      return NULL;
  }
  
  int main() 
  {
      printf("First number: ");
      scanf("%d",&amp;global[0]);
  
      printf("Second number: ");
      scanf("%d",&amp;global[1]);
  
      pthread_t tid_sum;
      pthread_create(&amp;tid_sum,NULL,sum_thread,(void*)&amp;global);
      pthread_join(tid_sum,NULL);
  
      return 0;
  }
  </code></pre>
  
  <p>However, when I run the code, it does not work properly due to a segmentation fault. I suppose I am trying to access/use unallocated memory. Should I allocate it with malloc or is there other things I am doing wrong?</p>