NULL is a macro defined in several standard headers, 0 is an integer constant, '\0' is a character constant, and nul is the name of the character constant. All of these are not interchangeable:
NULL is to be used for pointers only since it may be defined as ((void *)0), this would cause problems with anything but pointers.
0 can be used anywhere, it is the generic symbol for each type's zero value and the compiler will sort things out.
'\0' should be used only in a character context.
nul is not defined in C or C++, it shouldn't be used unless you define it yourself in a suitable manner, like:
#define nul '\0'
翻譯一下就是:
NULL是一個宏,它在幾個標準頭文件中定義,0是一個整型常量,'\0'是一個字符常量,而NUL是一個字符常量的名字。這幾個術語都不可互換。
1、NULL用於表示什麼也不指向,也就是空指針((void *)0)
2、0可以被用於任何地方,它是表示各種類型零值的符號並且編譯器會挑出它
3、'\0'應該只被用於結束字符串
4、NUL沒有被定義於C和C++,它不應該被使用除非你自己定義它,像:#define nul '\0'