Memory Stack or Heap

Which type of memory(stack or heap)is used by static and external variables?

Questions by rajeevpk4

Showing Answers 1 - 24 of 24 Answers

alokag

  • Jun 25th, 2009
 

Fully agree with vivekbansal. Static variables (not initialized to value other than 0) are always stored in BSS else in "Data" of data segment.

niyas15

  • Mar 2nd, 2010
 

The static variable is stored at data section and local variables are stored at stack and dynamic allocation of data are strored at heep

  Was this answer useful?  Yes

kbjarnason

  • Jul 1st, 2010
 

Since C has no concept of "stack", the question of whether stack or heap memory is used seems a bit unclear.

Static variables come in two distinct flavours: file scope and block scope.  Static file scope variables are differentiated from external/public file scope variables by having internal linkage. 

Further, static variables have static storage duration, they live for the lifetime of the program, and are initialized once, prior to program start.

For block local static variables, an effective means to manage them is either on a system stack memory (if it has one) or with a stack-like structure, but this is an implementation detail; the language does not specify how such are stored, only the requirements on initialization, lifetime and visibility (scope).

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions