title: C: How to dereference void**?
body: <p>Consider the following code:</p>
  
  <pre><code>void* run(void* arg) {
      int* array=(int*)arg;
  
      printf("In run!\n");
      int i;  
      for (i=0; i&lt;10; i++) {
          printf("%d ",array[i]);
      }
      printf("\n");
  
      return (void*)15;
  }
  
  
  
  int main() {
  
      pthread_t my_thread;
      int array[10]={0};
      void* ret;
  
      int i;
      for (i=0; i&lt;10; i++) {
          array[i]=i+1;
      }
  
      if (pthread_create(&amp;my_thread, NULL, run, (void*)array)!=0) {
          perror("thread creation failed");
          return 1;
      }
  
      pthread_join(my_thread, &amp;ret);
  
      printf("thread finished and returned %d\n", *(int*)ret); // segfault. why??
      return 0;
  
  }
  </code></pre>
  
  <p>I'm trying to obtain the value 15, returned by the thread that was created, but for some reason, that last printf throws segmentation fault.<br>
  What is the reason for the segmentation fault, and what is the right way to obtain the returned value 15?<br>
  I also tried this:<br>
  <code>printf("thread finished and returned %d\n", *(*(int*)ret));</code><br>
  Which resulted in an error:<br>
  <strong>error: invalid type argument of unary ‘*’ (have ‘int’)</strong><br>
  and this:<br>
  <code>printf("thread finished and returned %d\n", *(int*)(*ret));</code><br>
  which also resulted in an error (and a warning):<br>
  <strong>warning: dereferencing ‘void *’ pointer [enabled by default]<br>
  error: invalid use of void expression</strong></p>
  
  <p>What is the right way to do it, and most importantly, what is the reason for that segfault?</p>