title: When passing an array to a function in C++, why won't sizeof() work the same as in the main function?
body: <p>So my C++ instructor told us in class that there was no function to determine an array size in C++ and I was not satisfied with that. I found a question here on stackoverflow that gave this bit of code <code>(sizeof(array)/sizeof(*array))</code> and while I don't exactly understand it, I understand it takes the total amount of memory allocated to the array and divides it by what I assume is the default memory allocation of its data type...(???) 
  I decided I wanted to practice writing functions (I'm in CS 111 - Fundamentals 1) and write a function that returned the number of elements in any array I passed it. This is what I wrote:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int length_of_array(int some_list[])
  {
      // This only returns the integer 1 for some reason
     return (sizeof(some_list)/sizeof(*some_list));
  }
  
  int main()
  {
      // Declare and initialize an array with 15 elements
      int num_list[] = {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30};
  
      //Outputs what I assume is the total size in bytes of the array
      cout &lt;&lt; sizeof(num_list) &lt;&lt; endl;
  
      //Outputs what I assume to be size of memory set aside for each in element in an array
      cout &lt;&lt; sizeof(*num_list) &lt;&lt; endl;
  
      //This extrapolates array's number of elements
      cout &lt;&lt; "This is the output from direct coding in the\nint main function:\n" &lt;&lt;
              (sizeof(num_list)/sizeof(*num_list)) &lt;&lt; endl;
  
      //This function should return the value 15 but does not
      int length = length_of_array(num_list);
  
      cout &lt;&lt; "This is the length of the array determined\n";
      cout &lt;&lt; "by the length_of_array function:\n"  &lt;&lt; length &lt;&lt; endl;
  
  
  
      return 0;
  }
  </code></pre>
  
  <p>The function returns 1 no matter what I do. Would somebody please give me a C++ specific workaround and explanation of how it works? 
  Thank you.</p>