title: In C, I'm having trouble getting the pointed value of a member struct(a double pointer). The value is lost outside the function assigning the value
body: <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;pthread.h&gt;
  
  typedef struct {
    double *presult;
  } SomeData;
  
  //Fonction that assigns the value to be pointed
  void  *assignValue(void *data) {
      SomeData *aData = (SomeData*)data;
      double valeurTotal = 45.50;
  
      aData-&gt;presult = &amp;valeurTotal; //Make the pointer point to the value
  
      printf("%10.3f \n",*aData-&gt;presult); //Here it prints the right answer L 45.50
      pthread_exit(NULL);
  }
  
  int main(int argc, char *argv[]) {
      SomeData myData; // The struct
      pthread_t onethread; 
      pthread_create(&amp;onethread, NULL, assignValue,(void *)&amp;myData); 
      pthread_join(onethread, NULL);
  
      printf("**************************************** \n");
      printf("%10.3f \n", (myData.presult)); // prints: 0
      printf("%10.3f \n", *(myData.presult));// prints: 0
  
      exit(0);
  }
  </code></pre>
  
  <p>Question might be confusing, so hopefully this simplified version of my code can explain better. So basically, I've created a thread that modifies the values of a struct.</p>
  
  <p>Inside the thread function, the struct is passed-on as a pointer. One of the struct's member is a double pointer 'presult'. The thread function makes the 'presult' point to a value and it seems to work, because the print works.</p>
  
  <p>However, back into the main function, I try to print the value of 'presult' again, but it doesn't print 45.50, but 0.0 instead.</p>
  
  <p>In my full code, I actually get Segmentation fault with the last print. But even in this simplified code, it doesn't work. It doesn't print 45.50.</p>
  
  <p>Output is as followed:</p>
  
  <pre><code>45.50
  ****************************************
  0.000
  0.000
  </code></pre>
  
  <p>Any help is appreciated. Thank you.</p>