Interview Questions

Return a null pointer or a pointer to 0 bytes?

C Interview Questions and Answers


(Continued from previous question...)

Return a null pointer or a pointer to 0 bytes?

Q: What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

A: The ANSI/ISO Standard says that it may do either; the behavior is implementation-defined ortable code must either take care not to call malloc(0), or be prepared for the possibility of a null return.

(Continued on next question...)

Other Interview Questions