In C, there show up to be differences between assorted worths of zero -- NULL, NUL and 0.

You are watching: What is in c++

I understand that the ASCII character "0" evaluates to 48 or 0x30.

The NULL reminder is generally defined as:

#define NULL 0Or

#define NULL (void *)0In addition, tbelow is the NUL character "" which appears to evaluate to 0 as well.

Are tright here times as soon as these three values have the right to not be equal?

Is this also true on 64 little bit systems?



Note: This answer uses to the C language, not C++.

Null Pointers

The integer consistent literal 0 has actually different definitions relying on the context in which it"s used. In all situations, it is still an integer constant via the value 0, it is simply explained in various means.

If a tip is being compared to the continuous literal 0, then this is a examine to check out if the guideline is a null pointer. This 0 is then described as a null reminder consistent. The C typical defines that 0 actors to the type void * is both a null tip and a null pointer continuous.

Additionally, to assist readcapability, the macro NULL is offered in the header file stddef.h. Depending upon your compiler it might be possible to #undef NULL and also respecify it to somepoint wacky.

Therefore, below are some valid means to check for a null pointer:

if (guideline == NULL)NULL is defined to compare equal to a null tip. It is implementation identified what the actual meaning of NULL is, as long as it is a valid null guideline constant.

if (pointer == 0)0 is an additional representation of the null reminder constant.

if (!pointer)This if statement implicitly checks "is not 0", so we reverse that to expect "is 0".

The complying with are INVALID ways to check for a null pointer:

int mynull = 0;if (reminder == mynull)To the compiler this is not a inspect for a null pointer, but an ehigh quality inspect on two variables. This might work-related if mynull never before alters in the code and also the compiler optimizations consistent fold the 0 right into the if statement, however this is not guaranteed and the compiler hregarding produce at least one diagnostic message (warning or error) according to the C Standard.

Note that the worth of a null tip in the C language does not issue on the underlying style. If the underlying style has actually a null tip worth identified as deal with 0xDEADBEEF, then it is as much as the compiler to sort this mess out.

Because of this, even on this funny architecture, the following ways are still valid methods to check for a null pointer:

if (!pointer)if (reminder == NULL)if (guideline == 0)The following are INVALID methods to examine for a null pointer:

#specify MYNULL (void *) 0xDEADBEEFif (tip == MYNULL)if (pointer == 0xDEADBEEF)as these are viewed by a compiler as normal comparisons.

Null Characters

"" is characterized to be a null character - that is a character with all bits set to zero. "" is (prefer all character literals) an integer continuous, in this instance via the value zero. So "" is entirely tantamount to an unadorned 0 integer consistent - the only distinction is in the intent that it conveys to a huguy reader ("I"m making use of this as a null character.").

"" has nothing to perform with pointers. However, you may see somepoint equivalent to this code:

if (!*char_pointer)checks if the char reminder is pointing at a null character.

if (*char_pointer)checks if the char pointer is pointing at a non-null character.

Don"t gain these confused via null pointers. Just because the bit depiction is the very same, and also this permits for some convenient cross over cases, they are not really the very same thing.

See more: Why Do I Stay High Lyrics By Bone Thugs Why Do I Stay High Lyrics By Bone Thugs


See Inquiry 5.3 of the comp.lang.c FAQ for more.See this pdf for the C traditional. Check out sections Pointers, paragraph 3.