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

Discussion

Why is calloc() function used for?

  • A.allocates the specified number of bytes
  • B.allocates the specified number of bytes and initializes them to zero
  • C.increases or decreases the size of the specified block of memory and reallocates it if needed
  • D.calls the specified block of memory for execution

Answer: B

Correct answer: allocates the specified number of bytes and initializes them to zero

calloc does two things where malloc does one: it allocates the storage and sets every byte of it to zero.

It also takes its size as a count and an element size rather than a single total, and it is required to detect overflow in the product of the two - a check a hand-written malloc(m * n) does not get. Resizing an existing block is realloc's work, described by the third option.

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

Post your comment

Please log in or register to post a comment.