0

Hi,

I have a query regarding to the storage of program that: Where dose c-program instructions get stored? And where dose local variables get stored in memory?

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Salem
0

Local variables are stored in the call stack, together with the return address and passing parameters.

Instructions are stored in the code segment, which is usually at the lower part of the memory to prevent stack overflow from overwriting it.

0

> which is usually at the lower part of the memory to prevent stack overflow from overwriting it.
And where stacks grow downwards, that would be a problem right?

C doesn't actually require a "stack", only some memory which exhibits the property of allowing scoping. Since many machines have a conveniently large stack space, this is a convenient choice. But there are some machines where the native call stack is tiny, and another approach is required.

Also, the relative positions of the memory types is completely implementation defined, as is the direction in which the stack grows (if it has a stack at all).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.