title: Finding length of array inside a function
body: <p>In the program below the length of the array <code>ar</code> is correct in main but in <code>temp</code> it shows the length of the pointer to <code>ar</code> which on my computer is 2 (in units of <code>sizeof(int)</code>). </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void temp(int ar[]) // this could also be declared as `int *ar`
  {
      printf("%d\n", (int) sizeof(ar)/sizeof(int));
  }
  
  int main(void)
  {
      int ar[]={1,2,3};
      printf("%d\n", (int) sizeof(ar)/sizeof(int));
      temp(ar);
      return 0;
  }
  </code></pre>
  
  <p>I wanted to know how I should define the function so the length of the array is read correctly in the function.</p>