Is NULL always equal to 0(zero)? Ans. The answer depends on what you mean by 'equal to.' If you mean 'compares equal to,' such as if ( /* ... */ ) { p = NULL; } else { p = /* something else */; } /* ... */ if ( p == 0 ) then yes, NULL is always equal to 0. That's the whole point of the definition of a null pointer. If you mean 'is stored the same way as an integer zero,' the answer is no, not necessarily. That's the most common way to store a null pointer. On some machines, a different representation is used. The only way you're likely to tell that a null pointer isn't stored the same way as zero is by displaying a pointer in a debugger, or printing it. (If you cast a null pointer to an integer type, that might also show a nonzero value.) - Study24x7
Social learning Network
05 Apr 2023 12:56 PM study24x7 study24x7

Is NULL always equal to 0(zero)? Ans. The answer depends on what you mean by "equal to." If you mean "compares equal to," such as if ( /* ... */ ) { p = NULL; } else { p = /* something else */; } /* ... */ if ( p == 0 ) then yes, NULL is always equal to 0. That's the ...

See more

study24x7
Write a comment
Related Questions
500+   more Questions to answer
Most Related Articles