What is the behavior of malloc when the size requested is zero?

  • It goes into an infinite loop
  • It returns a null pointer (NULL)
  • It returns a pointer to a zero-sized memory block
  • It returns an error
When you request zero bytes of memory using malloc, it returns a null pointer (NULL) rather than allocating a zero-sized memory block. This is useful for special cases when you need a pointer that doesn't point to any memory.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *