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

Discussion

We use malloc and calloc for

  • A.Dynamic memory allocation
  • B.Static memory allocation
  • C.Both dynamic and static memory allocation
  • D.None of the above

Answer: A

Correct answer: Dynamic memory allocation

malloc and calloc obtain storage at run time from the heap, in a quantity that may be computed rather than fixed in the source. That is what dynamic allocation means.

Static allocation is settled by the compiler: globals and static variables are laid out before the program runs, and automatic variables are allocated by the function prologue. Neither requires a library call, which is the practical signal that they are a different mechanism. Dynamically allocated storage must be released with free; static storage never is.

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

Post your comment

Please log in or register to post a comment.