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

Discussion

If malloc() successfully allocates memory it returns the number of bytes it has allocated.

  • A.TRUE
  • B.FALSE
  • C.May Be
  • D.Can't Say

Answer: B

Correct answer: FALSE

malloc returns a pointer to the allocated block, not a count of bytes. On success it is the address of the storage; on failure it is null.

The number of bytes is what the caller supplied as the argument, so returning it would convey nothing. There is in fact no portable way to ask how large an allocated block is once it has been made, which is why programs that need to know must record the size themselves alongside the pointer.

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

Post your comment

Please log in or register to post a comment.