The run-time size of the array can be obtained using sizeof arr
. This will result in the same value as i * sizeof *arr
, and it could very result in the same code.
If not, how do you know at runtime how much to decrement the stack pointer once the array goes out of scope?
The size of the array is not needed to reset for this. A stack frame can be removed by simply restored the stack pointer to its previous value.