In the first case, a
itself occupies sizeof(int *)
bytes of automatic storage, and that points to 10 * sizeof(int)
bytes of dynamic storage.
In the latter case, b
occupies 10 * sizeof(int)
bytes of automatic storage. Because b
is an array, there is no pointer.
So the first case uses more total bytes, but less on the stack (assuming a stack is in use for automatic storage).
If the total number of bytes being used is relatively small, automatic storage is typically fine. For larger amounts, dynamic storage is preferred. For stack implementations in particular, having too many automatic variables that are too large can overflow the stack.