title: Modifying a struct member via a pointer in a function
body: <p>I have tried to go for pseudo code to try to focus on the problem and remove anything extraneous. I have a definition of a struct in a header file:</p>
  
  <p><strong>struct.h</strong></p>
  
  <pre><code>typedef struct {
      int value;
  } structname;
  
  static structname struct_array[NUMBER];
  </code></pre>
  
  <p><strong>start.c</strong></p>
  
  <pre><code>#include "struct.h"
  
  static void functionA() {
      function1 (&amp;struct_array[index]);
  }
  </code></pre>
  
  <p><strong>Setup.c</strong></p>
  
  <pre><code>#include "struct.h"
  
  int function1(structname * name) {
      int result = 0;   
      name-&gt;value = 2;   
      printf("The value before function2: d", result-&gt;value);   
      result = function2(name);   
      printf("The resulting value: d", result-&gt;value);
      printf("The address of the member to be modified is: %p", &amp;(name-&gt;value));   
      return result;
  }
  </code></pre>
  
  <p><strong>Modification.c</strong> </p>
  
  <pre><code>#include "struct.h"
  
  int function2(structname * name) {
      int result = 0;
      name-&gt;value = 1;
      printf("The resulting value: d", name-&gt;value);
      printf("The address of the member to be modified is: %p", &amp;(name-&gt;value));
      return result;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>This returns:</strong> </p>
  
  <pre><code>The value before function2: 2
  The resulting value: 1
  The address of the member to be modified is: 12345
  The resulting value:  2
  The address of the member to be modified is: 12345
  </code></pre>
  
  <p>Here's the thing: the addresses are the same. How can the functions appear to be modifying a member of a struct but upon return of the function, the struct member retains its original value?</p>
  
  <p>Should I be using the <code>extern</code> keyword? How and where?</p>
  
  <p>Edit:
  I thought I would do some tests to see if I could perhaps find the issue. All I have done is to confuse myself. So it turns out, if I add a second member to the struct, say int nextValue, the modification works on that and returns, and I can test it, and it is modified. So how can it work on one member and not another?! I'm flummoxed. Any ideas of perhaps what to test?</p>