Is NULL always zero in C?

chi42 picture chi42 · Mar 27, 2012 · Viewed 37.2k times · Source

I was interviewing a guy for a mid-level software engineering position yesterday, and he mentioned that in C, NULL is not always zero and that he had seen implementations of C where NULL is not zero. I find this highly suspect, but I want to be sure. Anyone know if he is right?

(Responses will not affect my judgement on this candidate, I've already submitted my decision to my manager.)

Answer

Oliver Charlesworth picture Oliver Charlesworth · Mar 27, 2012

I'm assuming you mean the null pointer. It is guaranteed to compare equal to 0.1 But it doesn't have to be represented with all-zero bits.2

See also the comp.lang.c FAQ on null pointers.


  1. See C99, 6.3.2.3.
  2. There's no explicit claim; but see the footnote for C99, 7.20.3 (thanks to @birryree in the comments).