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

Discussion

What does malloc() return if the requested memory cannot be allocated ?

  • A.0 as an integer
  • B.A NULL pointer
  • C.A pointer to the last free block
  • D.It terminates the program

Answer: C

Correct answer: A NULL pointer

On failure malloc() returns a null pointer, so every allocation should be tested before the pointer is used. Dereferencing the result without checking is one of the commonest causes of a crash in C.

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

Post your comment

Please log in or register to post a comment.