In programming languages like C and C++, people often refer to static and dynamic memory allocation. I understand the concept but the phrase \"All memory was allocated (rese
I would like to explain these concepts with the help of few diagrams.
This is true that memory cannot be allocated at compile time, for sure. But, then what happens in fact at compile time.
Here comes the explanation. Say, for example a program has four variables x,y,z and k. Now, at compile time it simply makes a memory map, where the location of these variables with respect to each other is ascertained. This diagram will illustrate it better.
Now imagine, no program is running in memory. This I show by a big empty rectangle.

Next, the first instance of this program is executed. You can visualize it as follows. This is the time when actually memory is allocated.

When second instance of this program is running, the memory would look like as follows.

And the third ..

So on and so forth.
I hope this visualization explains this concept well.