๐ŸŒ
Javatpoint
javatpoint.com โ€บ null-pointer-in-c
Null Pointer in C - javatpoint
Null Pointer in C with programming examples for beginners and professionals covering concepts, control statements, c array, c pointers, c structures, c union, c strings and more.
a value indicating that a pointer does not refer to a valid object
In computing, a null pointer (sometimes shortened to nullptr or null) or null reference is a value indicating that the pointer or reference does not refer to an object. Programs routinely use โ€ฆ Wikipedia
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Null_pointer
Null pointer - Wikipedia
June 13, 2026 - However, C++11 introduced the explicit null pointer constant nullptr and type nullptr_t to be used instead, providing a type-safe null pointer. nullptr and type nullptr_t were later introduced to C in C23. Programming languages use different literals for the null pointer. In Java and C#, the ...
Discussions

Trying to understand NULL pointers
NULL is equivalent to 0 and equivalent to nullptr (in C++). It's an address that is "universally invalid." You can store 0x2093704802934 in a pointer and it will be invalid too (I'm sure) but it's not a convention. NULL is this convention that says "the pointer is not valid" and/or "the pointer hasn't been initialized yet" or "the memory pointed to has been released and I have invalidated the pointer by setting it to NULL." You store this value in a "pointer", like "int* s = 0" to show that it is not pointing to anything. And in your code you will check whether the pointer (s in my example) is equal to NULL (invalid) or not (valid). First you create a pointer, then you initialize it, then you use it, then you release it. More on reddit.com
๐ŸŒ r/learnprogramming
18
1
December 30, 2021
what is a null pointer in c - Stack Overflow
I tried looking online but I didn't know exactly what to type. The Google search results I got for 'NULL pointer' were different from what I expected. ... There is also a typo in n2.next = &n2;, meaning that we will never reach n3. I would just throw this bad example away and study some other code. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Why is there a NULL in the C language? - Stack Overflow
But NULL may be defined like ((void*)0) in C (not in C++). ... it is more readable to use NULL about a pointer rather than to use 0. When you see if (a == NULL) that help you to know a is (very probably) a pointer. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Why do we use Null pointers?
The value where a null pointer is pointing is irrelevant. A null pointer is a pointer that is pointing nowhere--there is no value. In C, the number 0 was defined as the representation of the null pointer. They could have picked any number, but it would have been painful. More on reddit.com
๐ŸŒ r/C_Programming
56
0
August 30, 2024
๐ŸŒ
CSEstack
csestack.org โ€บ home โ€บ 3 major use of null pointer in c programming | what does actually null means?
3 Major use of NULL Pointer in C Programming | What does actually NULL means?
March 9, 2019 - ... It is a special marker or keyword which has no value. Each programming language has its own nuance. In most of the programming language including C, Java, typically, 0 (zero) is a NULL and predefined constant or Macro.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ trying to understand null pointers
r/learnprogramming on Reddit: Trying to understand NULL pointers
December 30, 2021 -

Hello all again,

I have another stupid question here lol, so I'm trying to wrap my head around NULL. Im currently under the impression that NULL is a built in constant that has a value of zero, but what does that actually mean? When would it be appropriate to use null? If someone could explain it in layman's terms that would be super helpful!

๐ŸŒ
Sanfoundry
sanfoundry.com โ€บ c-tutorials-null-pointer
NULL Pointer in C Programming with Examples - Sanfoundry
December 31, 2025 - Using NULL pointers serves several purposes:โ€‹ ยท โšก Claim Your Free Java Certification - August 2026 ยท Initialization: Assigning NULL to pointers during declaration helps in avoiding undefined behavior due to uninitialized pointers.โ€‹ ยท ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ null-pointer-in-c
NULL Pointer in C - GeeksforGeeks
To initialize a pointer variable when that pointer variable hasn't been assigned any valid memory address yet. To check for a null pointer before accessing any pointer variable.
Published: January 10, 2025
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_null.php
C NULL
It helps you avoid using pointers that are empty or invalid. You can compare a pointer to NULL to check if it is safe to use.
๐ŸŒ
Lysator
lysator.liu.se โ€บ c โ€บ c-faq โ€บ c-1.html
Null Pointers
To generate a null pointer in a function call context, an explicit cast is typically required, to force the 0 to be in a pointer context: ... If the (char *) cast were omitted, the compiler would not know to pass a null pointer, and would pass an integer 0 instead.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ pointers โ€บ null pointer
C | Pointers | Null Pointer | Codecademy
February 3, 2025 - Functions that involve memory ... memory, if the allocation fails, it returns NULL. ... In C, NULL is often defined as ((void \*)0)....
๐ŸŒ
StudyMite
studymite.com โ€บ blog โ€บ null-pointers-in-c
Null Pointer in C C Programming | StudyMite
August 2, 2026 - A null pointer points to nothing. It is assigned the value NULL, therefore it is called the null pointer. If you do not want the pointer to store any address then assign it to NULL.
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ all about c language โ€บ null pointer in c
Null Pointer In C
January 17, 2023 - #include<stdio.h> int main() { int * ptr =NULL; // declaration of null pointer if(ptr!=NULL) { printf("Value of ptr is : %d",* ptr); } else { printf("Pointer is invalid"); } return 0; } ... Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is null pointer in c?
What is Null Pointer in C? - Scaler Topics
September 4, 2023 - In the C programming language, a null pointer is a pointer that does not point to any memory location and hence does not hold the address of any variables. It just stores the segment's base address. That is, the null pointer in C holds the value Null, but the type of the pointer is void.
๐ŸŒ
ScienceDirect
sciencedirect.com โ€บ topics โ€บ computer-science โ€บ null-pointer
Null Pointer - an overview | ScienceDirect Topics
In C, Pascal, or Ada, which employ a value model, the assignment A := B puts the value of B into A. If we want B to refer to an object, and we want A := B to make A refer to the object to which B refers, then A and B must be pointers. In Clu and Smalltalk, which employ a reference model, the assignment A := B always makes A refer to the same object to which B refers. Java charts an intermediate course, in which the usual implementation of the reference model is made explicit in the language semantics.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ c programming tutorial โ€บ null pointer in c
Null pointer in C | How Null pointer work in C with Examples
March 28, 2023 - In C programming language pointers are used to point to the memory that is allocated dynamically or at run time and a pointer can be of any data type like int, float, char, etc. In this article, we are discussing the null pointer in C, where NULL is constant with value 0 in C.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Medium
medium.com โ€บ @shlomohassid โ€บ null-how-do-you-define-nothing-and-why-would-you-07683bdbe63a
NULL: How Do You Define Nothing? And Why Would You? | by Momi | Medium
May 31, 2025 - Attempting to read or write through a null pointer typically causes a runtime error or crash. In C and C++, this often manifests as the dreaded segmentation fault (accessing memory you shouldnโ€™t). In higher-level languages like Java or C#, it throws a runtime exception ( NullPointerException in Java, for instance).
Top answer
1 of 5
7

Actually, you can use a literal 0 anyplace you would use NULL.

Section 6.3.2.3p3 of the C standard states:

An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.

And section 7.19p3 states:

The macros are:

NULL

which expands to an implementation-defined null pointer constant

So 0 qualifies as a null pointer constant, as does (void *)0 and NULL. The use of NULL is preferred however as it makes it more evident to the reader that a null pointer is being used and not the integer value 0.

2 of 5
5

NULL is used to make it clear it is a pointer type.

Ideally, the C implementation would define NULL as ((void *) 0) or something equivalent, and programmers would always use NULL when they want a null pointer constant.

If this is done, then, when a programmer has, for example, an int *x and accidentally writes *x = NULL;, then the compiler can recognize that a mistake has been made, because the left side of = has type int, and the right side has type void *, and this is not a proper combination for assignment.

In contrast, if the programmer accidentally writes *x = 0; instead of x = 0;, then the compiler cannot recognize this mistake, because the left side has type int, and the right side has type int, and that is a valid combination.

Thus, when NULL is defined well and is used, mistakes are detected earlier.

In particular answer to your question โ€œIs there a context in which just plain literal 0 would not work exactly the same?โ€:

  • In correct code, NULL and 0 may be used interchangeably as null pointer constants.
  • 0 will function as an integer (non-pointer) constant, but NULL might not, depending on how the C implementation defines it.
  • For the purpose of detecting errors, NULL and 0 do not work exactly the same; using NULL with a good definition serves to help detect some mistakes that using 0 does not.

The C standard allows 0 to be used for null pointer constants for historic reasons. However, this is not beneficial except for allowing previously written code to compile in compilers using current C standards. New code should avoid using 0 as a null pointer constant.

๐ŸŒ
Udemy
blog.udemy.com โ€บ home โ€บ it & development โ€บ software development โ€บ understanding null pointer exception
Understanding Null Pointer Exception - Udemy Blog
April 14, 2026 - A null pointer exception crashes your program when code tries to use a reference variable pointing to null. This article covers how it occurs in Java and C#, and two ways to handle it: null checks and try-catch blocks.