Yes. This way you can use the NULL macro. This is a null pointer constant that is 0 .
When C requires the Boolean value of the expression, a false value is output when the expression is compared to zero, and the true value otherwise. That is, whenever you write
if(expr)
where expr is any expression in general, the compiler essentially acts as if it were written as
if((expr) != 0)
Substituting the trivial expression of the pointer p for expr , we have
if(p) is equivalent to if(p != 0)
and this is a comparison context, so the compiler can say that (implicit) 0 is actually a null pointer constant and uses the correct null pointer value. There is no deception; compilers work this way and generate identical code for both constructs. The internal representation of the null pointer does not matter .
but it is mentioned that it can be represented as a value that does not contain all zeros.
Yes. True. But the view does not matter in this case:
Whenever a programmer requests a null pointer, either by writing 0 or NULL , the compiler's responsibility is to generate any bit pattern used by the machine for that null pointer .
source share