Staic allocation and dynamic allocation

Lets say I have following code...

    int a;

Now memory allocation may happen at run time depending on the variable pass.

So memory allocation on stack also may happen at runtime as this allocation cant happen at compile time?

Then why do we call allocation for static variables static allocation and for heap variables we call it runtime memory allocation??

Please help

Thanks in advance!
The terms for memory allocation that I've always heard used are either stack/heap allocation or static/dynamic allocation.

Whoever used the term run-time allocation was probably just using a short-cut. When you allocate a variable on the stack (as in line 3), the compiler knows exactly where the variable resides in memory (relative to the current stack frame) at compile time. When you allocate memory in the heap, the program won't know where the variable lives in memory until it is actually allocated--at run time.

So, in either case the memory isn't allocated until run time, but the relative address of the memory for stack allocation is known at compile time.

I would stick with static vs. dynamic allocation.

Thanks.I have got it.

Topic archived. No new replies allowed.