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'
resource from www.slyar.com.
一个"L"的NUL和两个"L"的NULL,牢记住下面的话,有助于回忆指针和ASCII码零的正确术语.
一个‘L’的NUL用于结束一个ASCII字符串,两个‘L’的NULL用于表示什么也不指向(空指针)。
当然如果出现了三个‘L’的NULLL,那就要检查一下有没有拼写错误了ASCII字符中零的位模式被称为‘NUL’。表示哪里也不指向的的特殊的指针则是‘NULL’。这两个术语不可互换。
NULL and NUL in C
最新推荐文章于 2022-11-09 12:49:50 发布