title: passing address of variable to a C function
body: <p>I'm relatively new to C. I'm trying to pass an address of a variable to a function, and then have that function assign a char pointer to this variable address which was passed. The compiler doesn't complain, but the code doesn't work properly either.</p>
  
  <pre><code>typedef enum {
      VAL_1,
      VAL_2
  } member_type;
  
  char *a1="Test 123";
  
  int func (member_type x, char *temp) {
  
      switch(x) {
          case VAL_1:
               temp = a1;
               return 1;
          case VAL_2:
               return 2;
      }
      return 0;
  }
  
  int main(){
  
      member_type b;
      static char *d1;
      b = VAL_1;
      printf("%p\n",&amp;d1);
  
      func(b, &amp;d1);
  
      printf("Val_1:%s\n",d1);
  
      return 0;
  }
  </code></pre>
  
  <p>I get the following error when I execute it:</p>
  
  <pre><code>-bash-3.00$ ./a.out
   0x500950
   Name:(null)
  </code></pre>
  
  <p>Can anyone help me with how to fix it?</p>