title: pass by reference a struct through multiple functions in C
body: <p>I am trying to pass a struct by reference through multiple functions but I am getting garbage value when I try to print the value of the struct in each function. How to correctly pass it by reference, so that the value is passed back until from <code>func3() -&gt; func2() -&gt; func1()-&gt; main()</code> function</p>
  
  <pre><code>typedef struct _buf {
     void  *ptr;
     size_t len;
  } buf;
  
  
  int func3(buf *x){
    x-&gt;ptr = 45;
    printf("func3 %s \n", (char *)x-&gt;ptr);
    return 0;
  }
  
  int func2(buf *x){
    func3(&amp;* x);
    printf("func2 %s \n", (char *)x-&gt;ptr);
    return 0;
  }
  
  
  int func1(buf *x) {
    func2(&amp;*x);
    printf("func1 %s \n", (char *)x-&gt;ptr);
    return 0;
  }
  
  
  int main() {
    buf x = {NULL, 0};
    func1(&amp;x);
    printf("main %s \n", (char *)x.ptr);
    return 0;
  }
  </code></pre>