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.
Loading...
Related Quiz
- How can double pointers be used in dynamic memory allocation in C?
- The ________ directive can be used in C to include a file only once in a program.
- In what scenario would using a nested structure be beneficial?
- When you increment a pointer in C, it advances the pointer by the size of the type to which it points, which is known as ________.
- When reading a text file in C, which function can be used to read data from the file?