iceman19860106 said:
hello everyone!
what is the difference between NULL and 0 in C language?
NULL is a macro defined in <stdio.h>
It represents a null pointer constant, and may be defined either as 0 or as
((void *)0), which gives you a big hint that there's precious little
difference between them in semantic terms. The most important difference
is that 0 can definitely be used in contexts where an int is required,
whereas the possibility that NULL may be defined as ((void *)0) deters the
wary from using it in such contexts.
Thus, given this:
T *p = malloc(sizeof *p);
these are equivalent:
if(p != NULL)
and
if(p != 0)
They do the same thing with the same meaning.
But, given this:
int x;
these are not equivalent, or at least might not be:
x = 0;
and
x = NULL; /* if NULL is ((void *)0), which it can be,
this will cause a diagnostic message
*/
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999