title: Size of an array C++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1328223/sizeof-array-passed-as-parameter">Sizeof array passed as parameter</a>  </p>
  </blockquote>
  
  
  
  <p>I was wondering why the output of the following code is 1 and 9. Is that because of undeclared array in function size? How can I separate "size of array" to a function? </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  int size(int a[])
  {
      return sizeof a/sizeof a[0];
  }
  
  int main()
  {   
      int a[] = {5,2,4,7,1,8,9,10,6};
      cout &lt;&lt; size(a) &lt;&lt; endl;
      cout &lt;&lt; sizeof a/sizeof a[0] &lt;&lt; endl;
      system("pause");
      return 0;
  }
  </code></pre>