go to previous page   go to home page   go to next page hear noise

Answer:

a and b: (1) Storage for them exists only while the subroutine is active (while it has not yet returned control to its caller). (2) When it exists, the storage is on the run-time stack.

prompt1 and prompt2: (1) Storage for them exists while the program is in main storage. (2) Storage is in the data section of memory.


Storage Classes

memory

There are three places in memory where data may be placed: in the data section (declared with .data in assembly language), on the run-time stack, and on the heap.

A subroutine other than main() can have data in the .data section. In high-level programming languages, such as "C", this type of storage is called static.

Variables whose storage is allocated on the run-time stack are (sometimes) called automatic variables. This is because their storage is "automatically" pushed and popped as a subroutine is entered and exited. Usually the word "variable" means "automatic variable".

A variable whose memory is located in the heap is called a dynamic variable. Chapter 33 of these notes discusses the heap. The heap is where memory for objects is found (using the new operation in Java or C++). In "C" dynamic memory is allocated using the malloc operation (or similar).

The heap is on top of the data segment. As dynamic variables are created it grows upward (towards the stack)


QUESTION 22:

(Review:) What happens if the stack and heap get larger and larger?