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

Discussion

What happens when realloc() cannot extend a block in place ?

  • A.It returns NULL and leaves the original block untouched forever
  • B.It allocates a new block, copies the contents and frees the old one
  • C.It truncates the block to the available size
  • D.It merges the block with the stack

Answer: C

Correct answer: It allocates a new block, copies the contents and frees the old one

When there is not enough adjacent free space, realloc() obtains a fresh block, copies the existing data across, releases the old block and returns the new address. This is why the returned pointer must always be captured rather than assumed unchanged.

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

Post your comment

Please log in or register to post a comment.