title: Determine the size of a C++ array programmatically?
body: <p>This question was inspired by a similar question: <a href="https://stackoverflow.com/questions/197675/how-does-delete-know-the-size-of-the-operand-array">How does delete[] “know” the size of the operand array?</a></p>
  
  <p>My question is a little different:  <strong>Is there any way to determine the size of a C++ array programmatically?  And if not, why?</strong>  Every function I've seen that takes an array also requires an integer parameter to give it the size.  But as the linked question pointed out, <code>delete[]</code> must know the size of the memory to be deallocated.</p>
  
  <p>Consider this C++ code:</p>
  
  <pre><code>int* arr = new int[256];
  printf("Size of arr: %d\n", sizeof(arr));
  </code></pre>
  
  <p>This prints "<code>Size of arr: 4</code>", which is just the size of the pointer.  It would be nice to have some function which prints 256, but I don't think one exists in C++.  (Again, part of the question is why it doesn't exist.)</p>
  
  <p><strong>Clarification</strong>: I know that if I declared the array on the stack instead of the heap (i.e. "<code>int arr[256];</code>") that the <code>sizeof</code> operator would return 1024 (array length * sizeof(int)).</p>