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?

Recommended Answers

All 2 Replies

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.

> 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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.