Home Segments Index Top Previous Next

577: Mainline

You can, of course, also test for the null pointer by using the inequality operator, rather than the negation operator:

... 
if (trade_pointers [limit] != 0) { 
  free (trade_pointers[limit] -> description); 
  free (trade_pointers[limit]); 
} 
... 

Note, however, that most programmers prefer to substitute NULL for 0, as in the following example:

... 
if (trade_pointers [limit] != NULL) { 
  free (trade_pointers[limit] -> description); 
  free (trade_pointers[limit]); 
} 
... 

As you learned in Segment 516, NULL is a macro symbol that is replaced by 0 during compilation. 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.