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

Discussion

Which one is used during memory deallocation in C?

  • A.remove(p);
  • B.delete(p);
  • C.free(p);
  • D.terminate(p);

Answer: C

Correct answer: free(p);

free is the standard C deallocation function. It returns the block to the allocator, which may reuse it for a later request.

The other names belong elsewhere: delete is C++, and remove in C deletes a file rather than memory. Two conventions are worth keeping with free: passing NULL is explicitly defined to do nothing, so no guard is needed, and setting the pointer to NULL afterwards turns a later misuse into an immediate fault.

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

Post your comment

Please log in or register to post a comment.