title: Error in function for my pthread
body: <p>I have a program that takes in supposed to take in a number from a user <code>= (n)</code>, and create a thread to calculate the sum from 1 to n. I know that <code>((n+1)*n)/2</code> will give me the same result. When I run the program a thread is created but when I ask for the value of <code>'TotalSum'</code>, 0 is given instead of the calculation based on user input, why? </p>
  
  <pre><code># include &lt;stdio.h&gt;
  # include &lt;pthread.h&gt;
  
  void * thread_calc(void *);
  int TotalSum=0;
  
  int main()
  {
      int iNumber,iCount;
      pthread_t tid, tid2;
      printf("Enter Number Up to Which You want to Sum :");
      scanf("%d",&amp;iNumber);    
      pthread_create(&amp;tid,NULL,thread_calc,(void *) iNumber);
      //pthread_create(&amp;tid2,NULL,thread_calc,(void *)(iNumber+);
  
  
  
  
      printf("Thread %d running, Final Sum is : %d \n", tid,TotalSum);
      //printf("Thread %d running, Final Sum is : %d \n", tid2,TotalSum);
      //    return 0;
  }
  
  void *thread_calc(void *num)
  {
      int *iNumber;
      iNumber=(int*)num;
  
      TotalSum = ((*iNumber + 1)* (*iNumber))/2;
  
      pthread_exit(NULL);    
  }
  </code></pre>
  
  <p>My output: (For example, user enters 10)</p>
  
  <pre><code>Enter Number Up to Which You want to Sum :10
  Thread 536937120 running, Final Sum is : 0
  </code></pre>