Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between NUL and NULL? [duplicate]

Tags:

c

NULL is a macro defined in <stddef.h> for the null pointer; it can be defined as ((void*)0). NULL is the name of the first character in the ASCII character set. What is the difference between them?


2 Answers

NULL and NUL are of the same concept: They both represent the absence of a value. The only difference is - as you said - NULL is a macro in whereas NUL is the name given to the first ASCII character. The only scenario you are likely to come across a macro called NUL is something like this:

#define NUL '\0'
like image 131
Levi Avatar answered Oct 21 '25 17:10

Levi


Note that 0, NULL, '\0' and L'\0' are somewhat different:

sizeof(NULL) is the same as sizeof(void*), which is usually 8 on 64 bit Intel systems.

sizeof(0) is the same as sizeof(int), which is commonly still 4 on common 64 bit Intel systems.

sizeof('\0') is also the same as sizeof(int) in C, but is the same as sizeof(char) in C++ which has the value 1 by definition and is most likely different from sizeof(int).

sizeof(L'\0') is the same as sizeof(wchar_t), which is implementation defined.

Surprisingly, in C, you may have sizeof(L'\0') < sizeof('\0')

like image 27
chqrlie Avatar answered Oct 21 '25 18:10

chqrlie