Q. In not more than 10 words,
Define NULL in the context of a programming language.
And i came up with the following few answers:
- Null is absolutely Nothing. Zilch.
- Null is something which is NOT defined.
- Null is the return-value of a function which has nothing to return. †
- Null is the value of the pointer which points to nothing. ‡
- Null is the character at the end of a string.
- Null is the character with ASCII-code zero.
- Null is a byte with all its bits set to 0.
In fact,  &  are so generic that they are applicable even in other fields (ex. Mathematics).
, ,  &  are NOT definitions in the true sense. Rather they are commonly found implementations (or "Use-Cases") of NULL in programming languages.
Finally  gives us a one-line definition of NULL i.e. a byte with all its bits set to 0.
Now with reference to  we can see that-
- Since ASCII-code zero is a byte with all bits set to 0,  is the exact same definition but just in so many other words.
-  is NOT a definition of NULL. Rather it is a commonly found usage of NULL. One sees NULL terminated strings everywhere. It is so common that even programming-languages that do NOT have any explicit support for NULL, support lpStrZ i.e. null-terminated-strings.
-  mentions yet another very common usage of NULL. Pointers are usually used to pass references to data between functions. As a special "use-case" whenever the "sender" function encounters a case wherein it has no (valid) data to pass, it assigns the value NULL to the pointer thereby signaling to the "receiver" function that the pointer reference is invalid.
-  is yet another (not so common) usage of NULL. The following line
//end of function
found at the end of so many common functions in any given C-code is the line that implements it. By convention, any function that completes execution successfully and has nothing to report (except for the fact that it succeeded) returns a NULL (i.e. zero in this case). In case of errors the functions usually return non-zero values which indicate the kind of error they encounter.
" How a function pointer can even be the return value of a function...
...is really mind-bending, so stretch your brain a bit so as not to risk injury."
20 Qs. 20 straight answers.
EVERYTHING you ever wondered about NULL pointers.
____________ _ _ ____________
† If your function returns some data in some cases and no data in other cases, then define it as a non-void function and use NULL when you have nothing to return.
‡ Once a block of memory is freed, any pointers pointing to it must be set to NULL to prevent any accidental access.
BONUS: Here is an even more intriguing question that the one i had started with:
Q. What is the data-type of NULL?
Hint: NULL is just yet another value like 13, 3.14 or 'c'.