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?
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'
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With