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

Discussion

void * malloc(size_t n) returns:

  • A.Pointer to n bytes of uninitialized storage
  • B.NULL if the request cannot be satisfied
  • C.Nothing
  • D.Both a & b are true

Answer: D

Correct answer: Both a & b are true

Both statements describe malloc correctly. On success it returns a pointer to n bytes of uninitialised storage - the contents are whatever the allocator hands over, which is the difference from calloc.

On failure it returns NULL, and that is its only means of reporting failure. Checking the return value is therefore the caller's responsibility, and neglecting it is a common fault: the program dereferences a null pointer and crashes some distance from the real cause.

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

Post your comment

Please log in or register to post a comment.