while(foo) vs while(foo != NULL)
Can someone explain how while(foo) vs while(foo != NULL) are equivalent? Also: while(!foo) vs while(foo == NULL) I know that ! is not, but that is about all I know. Assuming foo is of pointer type, while (foo) and while (foo != NULL) are exactly equivalent. Both are also equivalent to while (foo != 0) . (In my opinion while (foo != NULL) more clearly expresses the intent.) In any context requiring a condition ( if() , while() , a few others), the expression is treated as true if the condition compares unequal to zero, false if it compares equal to zero. NULL is a macro that expands to an