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

前端 未结 11 1272
無奈伤痛
無奈伤痛 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 17:13

    A byte with a value of 0x00 is, on the ASCII table, the special character called NUL or NULL. In C, since you shouldn't embed control characters in your source code, this is represented in C strings with an escaped 0, i.e., \0.

    But a true NULL is not a value. It is the absence of a value. For a pointer, it means the pointer has nothing to point to. In a database, it means there is no value in a field (which is not the same thing as saying the field is blank, 0, or filled with spaces).

    The actual value a given system or database file format uses to represent a NULL isn't necessarily 0x00.

提交回复
热议问题