Machine-translated by Google. Questions are authored in English.
Top

Discussion

Local variables are stored in an area called ___________

  • A.Heap
  • B.Permanent storage area
  • C.Free memory
  • D.Stack

Answer: D

Correct answer: Stack

Local variables have automatic storage duration: created on entry to their block and destroyed on exit. A stack matches that pattern exactly, since the most recently created is always the first to be destroyed.

Allocation therefore costs only an adjustment of the stack pointer, which is why automatic variables are far cheaper than heap blocks. The same mechanism is why returning the address of a local is a fault - the storage is reclaimed as the function returns.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.