|
Hmmm.... I would have responded earlier, but I've been away due to a family emergency.
NULL is a macro that is specified in the C standard (declared in <stdlib.h>). In C++ it is supported in <cstdio> which might mean (i.e. I haven't checked the standard, so take this with a grain of salt) it is a constant in namespace std rather than a macro.
As Dawei said, if a pointer is initialised to zero the result is the same as if that pointer was assigned as the NULL pointer. Similarly, if a pointer is compared to zero (which includes tests like pointer == 0 or, more tersely, !pointer) the result is the same as if the pointer is compared to a NULL pointer of the same type (i.e. the test "pointer == 0" is the same as the test "pointer == NULL" or [more precisely] "pointer == (type_of_pointer *)NULL"). The NULL pointer is a special value of a pointer that effectively indicates "this pointer points at nothing".
Despite all this, there is no requirement that NULL be a zero value. The compiler is required to do a conversion of a zero to a NULL value behind the scenes when working with pointers. But the value of "0 == (int)NULL" is not required to give a true (or non-zero integer in C) result.
The declarations "LinkList list;" and "LinkedList list();" are equivalent in C++ if LinkedList has a default constructor (a constructor that accepts no arguments). In C++, naming a variable named list may confuse people (but not the compiler) as std::list is a template type in the standard library.
|