title: errors while trying to pass a structure to a function
body: <p>In the following program I try to pass a structure to a function. But I get errors,and I do not understand why. What mistake have I made in this program ?</p>
  
  <p>I am using <code>gcc</code> for compiling this <code>c</code> program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  struct tester {
    int x;
    int *ptr;
  };
  
  void function(tester t);
  
  int main() {
   tester t;
   t.x = 10;
   t.ptr = &amp; t.x;
   function(t);
  }
  
  void function(tester t) {
     printf("%d\n%p\n",t.x,t.ptr);
  }
  </code></pre>
  
  <hr>
  
  <p>Errors :</p>
  
  <pre><code>gcc tester.c -o tester
  
  tester.c:8:15: error: unknown type name ‘tester’
  tester.c: In function ‘main’:
  tester.c:12:2: error: unknown type name ‘tester’
  tester.c:13:3: error: request for member ‘x’ in something not a structure or union
  tester.c:14:3: error: request for member ‘ptr’ in something not a structure or union
  tester.c:14:13: error: request for member ‘x’ in something not a structure or union
  tester.c: At top level:
  tester.c:18:15: error: unknown type name ‘tester’
  </code></pre>
  
  <p><strong><em>NOTE</em> :</strong>  If I replace <code>printf</code> with <code>cout</code> and <code>stdio</code> with <code>iostream</code> and name the extension to <code>.cpp</code> (!), I get no errors. Why is that ? No wonder I compile it using <code>g++</code></p>