What does the ‘NULL’ keyword represent in C?
a) A zero value
b) A pointer that does not point to any object or function
c) An undefined value
d) A memory address
Answer:
b) A pointer that does not point to any object or function
Explanation:
In C, the NULL
keyword represents a pointer that does not point to any valid memory location, object, or function. It is often used to initialize pointers or to check if a pointer is pointing to something. For example, int *ptr = NULL;
means that ptr
is a pointer that currently does not point to any memory location.
Understanding the use of NULL
is crucial for managing pointers safely and avoiding dereferencing invalid memory locations, which can lead to undefined behavior in C programs.