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

Discussion

Memory allocation using malloc() is done in?

  • A.Static area
  • B.Stack area
  • C.Heap area
  • D.Both b & c

Answer: C

Correct answer: Heap area

malloc takes storage from the heap, a region the program grows at run time. That is what gives the block a lifetime independent of any function: it persists until free is called, whatever returns in the meantime.

The static area holds globals and static variables, laid out before the program starts, and the stack holds automatic variables, reclaimed on return. It is the heap's independence from function lifetimes that makes it the only place a data structure can be built and returned.

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

Post your comment

Please log in or register to post a comment.