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


Null Pointers

The integer constant literal 0 has different meanings depending upon the context in which it's used. In all cases, it is still an integer constant with the value 0, it is just described in different ways.

If a pointer is being compared to the constant literal 0, then this is a check to see if the pointer is a null pointer. This 0 is then referred to as a null pointer constant. The C standard defines that 0 cast to the type void * is both a null pointer and a null pointer constant.

Additionally, to help readability, the macro NULL is provided in the header file stddef.h. Depending upon your compiler it might be possible to #undef NULL and redefine it to something wacky.

Therefore, here are some valid ways to check for a null pointer:

if (pointer == NULL)

NULL is defined to compare equal to a null pointer. It is implementation defined what the actual definition of NULL is, as long as it is a valid null pointer constant.

if (pointer == 0)

0 is another representation of the null pointer constant.

if (!pointer)

This if statement implicitly checks "is not 0", so we reverse that to mean "is 0".

The following are INVALID ways to check for a null pointer:

int mynull = 0;
<some code>
if (pointer == mynull)

To the compiler this is not a check for a null pointer, but an equality check on two variables. This might work if mynull never changes in the code and the compiler optimizations constant fold the 0 into the if statement, but this is not guaranteed and the compiler has to produce at least one diagnostic message (warning or error) according to the C Standard.

Note that the value of a null pointer in the C language does not matter on the underlying architecture. If the underlying architecture has a null pointer value defined as address 0xDEADBEEF, then it is up to the compiler to sort this mess out.

As such, even on this funny architecture, the following ways are still valid ways to check for a null pointer:

if (!pointer)
if (pointer == NULL)
if (pointer == 0)

The following are INVALID ways to check for a null pointer:

#define MYNULL (void *) 0xDEADBEEF
if (pointer == MYNULL)
if (pointer == 0xDEADBEEF)

as these are seen by a compiler as normal comparisons.

Null Characters

'\0' is defined to be a null character - that is a character with all bits set to zero. '\0' is (like all character literals) an integer constant, in this case with the value zero. So '\0' is completely equivalent to an unadorned 0 integer constant - the only difference is in the intent that it conveys to a human reader ("I'm using this as a null character.").

'\0' has nothing to do with pointers. However, you may see something similar to this code:

if (!*char_pointer)

checks if the char pointer is pointing at a null character.

if (*char_pointer)

checks if the char pointer is pointing at a non-null character.

Don't get these confused with null pointers. Just because the bit representation is the same, and this allows for some convenient cross over cases, they are not really the same thing.

References

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

Top answer
1 of 11
445

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


Null Pointers

The integer constant literal 0 has different meanings depending upon the context in which it's used. In all cases, it is still an integer constant with the value 0, it is just described in different ways.

If a pointer is being compared to the constant literal 0, then this is a check to see if the pointer is a null pointer. This 0 is then referred to as a null pointer constant. The C standard defines that 0 cast to the type void * is both a null pointer and a null pointer constant.

Additionally, to help readability, the macro NULL is provided in the header file stddef.h. Depending upon your compiler it might be possible to #undef NULL and redefine it to something wacky.

Therefore, here are some valid ways to check for a null pointer:

if (pointer == NULL)

NULL is defined to compare equal to a null pointer. It is implementation defined what the actual definition of NULL is, as long as it is a valid null pointer constant.

if (pointer == 0)

0 is another representation of the null pointer constant.

if (!pointer)

This if statement implicitly checks "is not 0", so we reverse that to mean "is 0".

The following are INVALID ways to check for a null pointer:

int mynull = 0;
<some code>
if (pointer == mynull)

To the compiler this is not a check for a null pointer, but an equality check on two variables. This might work if mynull never changes in the code and the compiler optimizations constant fold the 0 into the if statement, but this is not guaranteed and the compiler has to produce at least one diagnostic message (warning or error) according to the C Standard.

Note that the value of a null pointer in the C language does not matter on the underlying architecture. If the underlying architecture has a null pointer value defined as address 0xDEADBEEF, then it is up to the compiler to sort this mess out.

As such, even on this funny architecture, the following ways are still valid ways to check for a null pointer:

if (!pointer)
if (pointer == NULL)
if (pointer == 0)

The following are INVALID ways to check for a null pointer:

#define MYNULL (void *) 0xDEADBEEF
if (pointer == MYNULL)
if (pointer == 0xDEADBEEF)

as these are seen by a compiler as normal comparisons.

Null Characters

'\0' is defined to be a null character - that is a character with all bits set to zero. '\0' is (like all character literals) an integer constant, in this case with the value zero. So '\0' is completely equivalent to an unadorned 0 integer constant - the only difference is in the intent that it conveys to a human reader ("I'm using this as a null character.").

'\0' has nothing to do with pointers. However, you may see something similar to this code:

if (!*char_pointer)

checks if the char pointer is pointing at a null character.

if (*char_pointer)

checks if the char pointer is pointing at a non-null character.

Don't get these confused with null pointers. Just because the bit representation is the same, and this allows for some convenient cross over cases, they are not really the same thing.

References

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

2 of 11
45

It appears that a number of people misunderstand what the differences between NULL, '\0' and 0 are. So, to explain, and in attempt to avoid repeating things said earlier:

A constant expression of type int with the value 0, or an expression of this type, cast to type void * is a null pointer constant, which if converted to a pointer becomes a null pointer. It is guaranteed by the standard to compare unequal to any pointer to any object or function.

NULL is a macro, defined in as a null pointer constant.

\0 is a construction used to represent the null character, used to terminate a string.

A null character is a byte which has all its bits set to 0.

Discussions

javascript - Why `null >= 0 && null <= 0` but not `null == 0`?
I had to write a routine that increments the value of a variable by 1 if its type is number and assigns 0 to the variable if not, where the variable is initially null or undefined. The first More on stackoverflow.com
🌐 stackoverflow.com
routing - What is Null 0 interface? - Network Engineering Stack Exchange
In which case is ip route 10.1.0.0 255.255.255.0 null0 used? Thanks in advance. This question is a repost of the same question in The Cisco Learning Network; however, the answers are unique to St... More on networkengineering.stackexchange.com
🌐 networkengineering.stackexchange.com
April 19, 2014
Why on earth does null == "0" give false as a result?
So, i am now totally confused , javascript says one thing and then does totally opposite , i went to articles and videos to read about == and === , they all said == makes values convert to number … So how on earth when Number(null) = 0 and Number(false) is 0 , do i get null == “0” as ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
13
0
February 10, 2018
Null 0 interface explanation
I'm developing a course concentrating on ACLs and how routers handle traffic. One of the topics I'm discussing is how Null 0 interfaces can be used to remove unwanted traffic. I've read the attached document from CISCO and it states that Null 0 interfaces can be used to remove unwanted traffic ... More on community.cisco.com
🌐 community.cisco.com
December 24, 2013
Top answer
1 of 16
104

To explain to a boss the difference between "zero" and "null":

"Zero" is a value. It is the unique, known quantity of zero, which is meaningful in arithmetic and other math.

"Null" is a non-value. It is a "placeholder" for a data value that is not known or not specified. It is only meaningful in this context; mathematical operations cannot be performed on null (the result of any such operation is undefined, and therefore also generally represented as null).

For example, as in the comments: "What is your yearly income?" is a question requiring a numeric answer. "0" is a perfectly valid answer for someone who does not work and has no investment income. If the user does not enter a value at all, they don't necessarily make no money; they just didn't want to tell your software how much (or little) they make. It's an unknown, not specified; therefore, to allow the software to continue, you specify the "null" placeholder for that data field within the software. That's technically valid from a data perspective; whether it's valid at the business level depends on whether an actual numeric value (even zero) is required in order to perform a mathematical operation (such as calculation of taxes, or comparison with thresholds determining benefits).

In computers, virtually any operation on a variable containing null will result either in null or in an error condition, because since one of the variable's values is not known, the result of the expression cannot be known. The equivalent of performing math on null would be if I asked you "What's five plus the number I'm thinking of right now?". It's impossible for you to give a definite answer because you don't know the number I'm thinking of. An operation on zero, except for dividing by it, is usually valid and will return another known, unique value.

2 of 16
174

Boss-speak is always tough...

Zero is a number so you can do things with it.

Null is a unicorn. It doesn't exist so you can't do anything at all with it.

Top answer
1 of 6
254

Your real question seem to be:

Why:

null >= 0; // true

But:

null == 0; // false

What really happens is that the Greater-than-or-equal Operator (>=), performs type coercion (ToPrimitive), with a hint type of Number, actually all the relational operators have this behavior.

null is treated in a special way by the Equals Operator (==). In a brief, it only coerces to undefined:

null == null; // true
null == undefined; // true

Values false, '0', and [] are subject to numeric coercion to zero. Strings coerce to zero when, after trimming whitespace, the result is the empty string ("").

You can see the inner details of this process in the The Abstract Equality Comparison Algorithm and The Abstract Relational Comparison Algorithm.

In Summary:

  • Relational Comparison: When ToPrimitive(null, hint: Number) is called, and both values are not type String, ToNumber is called on both. This is the same as adding a + in front, which for null coerces to 0.

This also explains how Date objects can be compared numerically.

As for null >= 0, as ToPrimitive(null, hint: Number) results null.

Null The result equals the input argument (no conversion).

For the "The Abstract Relational Comparison Algorithm" of EcmaScript 5.1, this occurs in step 3.

EcmaScript 2025, 7.2.12 IsLessThan ( x, y, LeftFirst ), step 4 the same effect. (see: https://tc39.es/ecma262/#sec-islessthan)

c. NOTE: Because px and py are primitive values, evaluation order is not important. d. Let nx be ? ToNumeric(px). e. Let ny be ? ToNumeric(py).

  • Equality Comparison: only calls ToNumber on Strings, Numbers, and Booleans.

7.1.4 ToNumber ( argument ) The abstract operation ToNumber takes argument argument (an ECMAScript language value) and returns either a normal completion containing a Number or a throw completion. It converts argument to a value of type Number. It performs the following steps when called:

  1. If argument is a Number, return argument.
  2. If argument is either a Symbol or a BigInt, throw a TypeError exception.
  3. If argument is undefined, return NaN.
  4. If argument is either null or false, return +0𝔽.
  5. If argument is true, return 1𝔽.
  6. If argument is a String, return StringToNumber(argument).
  7. Assert: argument is an Object.
  8. Let primValue be ? ToPrimitive(argument, NUMBER).
  9. Assert: primValue is not an Object.
  10. Return ? ToNumber(primValue).
2 of 6
23

I'd like to extend the question to further improve visibility of the problem:

null >= 0; //true
null <= 0; //true
null == 0; //false
null > 0;  //false
null < 0;  //false

It just makes no sense. Like human languages, these things need be learned by heart.

🌐
C For Dummies
c-for-dummies.com › blog
The Difference Between NULL and Zero | C For Dummies Blog
That’s the null character, which is used in C to terminate a string of text. The problem is that \0 translates into character value zero. In fact, you can use a zero directly (if you know how) and it has the same effect.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › difference-between-null-pointer-null-character-0-and-0-in-c-with-examples
Difference between NULL pointer, Null character ('\0') and '0' in C with Examples - GeeksforGeeks
July 15, 2025 - In all cases, it is an integer constant with the value 0, it is just described in different ways. If any pointer is being compared to 0, then this is a check to see if the pointer is a null pointer.
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › t › why-on-earth-does-null-0-give-false-as-a-result › 173701
Why on earth does null == "0" give false as a result? - The freeCodeCamp Forum
February 10, 2018 - So, i am now totally confused , javascript says one thing and then does totally opposite , i went to articles and videos to read about == and === , they all said == makes values convert to number … So how on earth when Number(null) = 0 and Number(false) is 0 , do i get null == “0” as ...
🌐
Medium
medium.com › @dilanblog › zero-0-vs-null-vs-undefined-understanding-the-differences-0e6a772bb2fa
Zero (0) vs Null vs Undefined: Understanding the Differences | by Dilan Nawarathne | Medium
January 23, 2025 - 2. `null` box: - This is also an empty box - But someone intentionally emptied this box - This is “intentionally emptied” · 3. `0` box: - This is not empty - This has a real value — which is 0 - This is not “emptiness”, this is a number
🌐
Cisco Community
community.cisco.com › t5 › routing › null-0-interface-explanation › td-p › 2414658
Solved: Null 0 interface explanation - Cisco Community
December 24, 2013 - I'm developing a course concentrating on ACLs and how routers handle traffic. One of the topics I'm discussing is how Null 0 interfaces can be used to remove unwanted traffic. I've read the attached document from CISCO and it states that Null 0 interfaces can be used to remove unwanted traffic without the overhead of ACLs.
🌐
Theinformationlab
theinformationlab.nl › 2020 › 08 › 31 › difference-between-null-and-0
What is the difference between NULL and 0 values?
August 31, 2020 - +44 (0) 8453 888 289 · INFO@THEINFORMATIONLAB.CO.UK · Services · About · Community · Events · Contact · Support · The Data School · Privacy Policy · Terms of Use · Cookie Policy ·
🌐
Medium
medium.com › @aaronlu5 › null-vs-0-which-would-you-use-in-code-47b7479cb5e3
Null vs 0, which would you use in code? | by Aaron Lu | Medium
May 7, 2025 - Clearly, in the context of money cost, 0 has its own natural meaning of “free of charge” or “no cost at all”, etc, while null means “not available yet”, “not applicable”, or “missing”, etc.
🌐
Sololearn
sololearn.com › en › Discuss › 345807 › are-null-and-zero-that-same-thing-in-c
Are NULL and zero that same thing in C++? | Sololearn: Learn to code for FREE!
Null basically have NO VALUE. & 0 is a numeric value itself. Null value is empty, undefined or not even initialized. When a variable is null then variable assign no any value, but if variable is 0 then it hold a integer in memory.
🌐
Quora
quora.com › What-is-the-actual-difference-between-NULL-and-0-zero
What is the actual difference between NULL and 0 (zero)? - Quora
In programming, NULL is supposed to indicate the absence of anything useful. In other words, whatever you asked for — it does not exist. On the other hand, 0 is a number with an actual meaning.
🌐
Wikipedia
en.wikipedia.org › wiki › Null_character
Null character - Wikipedia
March 3, 2026 - In a string literal, the null character is often represented as the escape sequence \0 (for example, "abc\0def"). Similar notation is often used for a character literal (i.e. '\0') although that is often equivalent to the numeric literal for ...
🌐
Medium
medium.com › @maxwellarmah01 › understanding-javascript-comparisons-why-0-is-null-and-not-null-372d84d65284
Understanding JavaScript Comparisons: Why 0 is null and not null | by Maxwell Armah | Medium
June 10, 2024 - Relational Comparison (`>=`): When `0 >= null` is evaluated, JavaScript first converts `null` to a number. `Number(null)` is `0`, so the comparison becomes `0 >= 0`, which is true.