nil, Nil and NULL what’s the difference?

If you use GCC, you will most probably never ever see a difference between this 3 keywords and can use them interchangeably. If you use another compiler, if you just wonder or if you care about writing semantically correct code then just keep reading.

  • nil is a null object pointer, (id)0 [that is the number 0 casted to the type id]
  • Nil is a null class pointer, (Class)0 [that is the number 0 casted to the type Class]
  • NULL is a null pointer constant, (void *)0 [it’s a preprocessor macro defined by ANSI C]

Then be carefull to use only nil whith object and not with a numerical primitive type. Otherwise you could have some unpleasant suprises.
Source for Objective-C and for ANSI C, NULL is standardly defined in stddef.h