You allocate to the stack when you’re defining things in a local scope where you know exactly the memory block size you need, such as primitive data types, arrays of a set size, etc.
The stack is a self-managing memory store that you don’t have to worry about – it’s super fast at allocating and clearing memory all by itself.
For other memory allocations, such as objects, buffers, strings, or global variables, you allocate to the heap.
Compared to the stack, the heap is not self-managing. Memory allocated to the heap will sit there throughout the duration of the program and can change state at any point in time as you manually allocate/deallocate to it.