What is the difference between NULL, '\0' and 0?

前端 未结 11 1274
無奈伤痛
無奈伤痛 2020-11-21 16:32

In C, there appear to be differences between various values of zero -- NULL, NUL and 0.

I know that the ASCII character

11条回答
  •  灰色年华
    2020-11-21 16:55

    It appears that a number of people misunderstand what the differences between NULL, '\0' and 0 are. So, to explain, and in attempt to avoid repeating things said earlier:

    A constant expression of type int with the value 0, or an expression of this type, cast to type void * is a null pointer constant, which if converted to a pointer becomes a null pointer. It is guaranteed by the standard to compare unequal to any pointer to any object or function.

    NULL is a macro, defined in as a null pointer constant.

    \0 is a construction used to represent the null character, used to terminate a string.

    A null character is a byte which has all its bits set to 0.

提交回复
热议问题