Home Segments Index Top Previous Next

734: Mainline

Many programmers prefer to assign pointer variables to the null pointer by using the NULL macro:

class header { 
  public:  link *first_link_pointer; 
           header ( ) { 
             first_link_pointer = NULL; 
           } 
           ... 
}; 

As explained in Segment 136, the C++ compiler replaces the characters in macros before regular compilation begins. Instances of the NULL macro, which happens to be declared in the iostream.h header file, are replaced by 0. By using NULL instead of 0, you identify the places where 0 is used as a special pointer, rather than as an ordinary integer, thereby increasing program clarity.