title: Question about converting `void *` to `int` in C
body: <p>I'm trying to pick my C skills again. I want to sum a sequence in different threads, each thread would return a pointer of the sum of a part of the sequence. However, when I tried to convert the <code>void*</code> type value <code>local_sum</code> to <code>int</code>, problem occurred. </p>
  
  <p>I tried to convert with <code>sum += *(int*)local_sum;</code>, a segment error occurred and I got <code>Process finished with exit code 11</code>. </p>
  
  <p>I found that if I use <code>sum += (int)local_sum;</code>, it would be okay. But I couldn't convince myself: shouldn't <code>local_sum</code> be a <code>void *</code>? Why it can be converted to <code>int</code> with <code>(int)local_sum</code>?</p>
  
  <p>I'm so grateful it you could answer the problem.</p>
  
  <p>The part that sum each process's return value is here:</p>
  
  <pre><code>int sum = 0;
  for (int i = 0; i &lt; NUM_THREADS; i ++) {
      void * local_sum;
      pthread_join(count_threads[i], (&amp;local_sum));
      sum += (int)local_sum;
  }
  </code></pre>
  
  <p>The function of a thread is here:</p>
  
  <pre><code>void * count_thr(void *arg) {
      int terminal = ARRAY_SIZE / NUM_THREADS;
      int sum = 0;
      for (int i = 0; i &lt; terminal; i ++) {
          sum += *((int*)arg + i);
      }
      return (void*)sum;
  }
  </code></pre>