title: C++ - passing an array of unknown size
body: <p>Trying to pass an int array of consecutive numbers starting with 1 but assuming the function receiving this array does not know it's length. When trying to calculate the length inside the function it just gives me 1 since it only finds the first element when calculating sizeof(arrayName).</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int Sum(int intArray[]) {
      int n = sizeof(intArray) / sizeof(*intArray);
      cout &lt;&lt; "Array size in function: " &lt;&lt; n &lt;&lt; endl;
      return n * (n + 1) / 2;
  }
  
  int main() {
      int anArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
      int arraySum = Sum(anArray);
  
      cout &lt;&lt; "Array size in main: " &lt;&lt; sizeof(anArray) / sizeof(*anArray) &lt;&lt; endl;
      cout &lt;&lt; "Sum is: " &lt;&lt; arraySum;
      int a;
      cin &gt;&gt; a;
      return 0;
  }
  </code></pre>