NULL

From cppreference.com
< cpp‎ | types
 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
(C++11)
NULL
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(deprecated in C++17)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
(C++11)
(C++11)
(C++11)
(C++11)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++17)
(C++11)(deprecated in C++17)(C++17)
 
Defined in header <cstddef>
Defined in header <cstring>
Defined in header <cwchar>
Defined in header <ctime>
Defined in header <cstdio>
Defined in header <clocale>
Defined in header <cstdlib>
#define NULL /*implementation-defined*/

The macro NULL is an implementation-defined null pointer constant, which may be

an integral constant expression rvalue of integer type that evaluates to zero

(until C++11)

an integer literal with value zero, or a prvalue of type std::nullptr_t

(since C++11)

A null pointer constant may be implicitly converted to any pointer type; such conversion results in the null pointer value of that type. If a null pointer constant has integer type, it may be converted to a prvalue of type std::nullptr_t.

Possible implementation

#define NULL 0
//since C++11
#define NULL nullptr

Notes

In C, the macro NULL may have the type void*, but that is not allowed in C++.

Example

#include <cstddef>
class S;
int main()
{
    int* p = NULL;
    int* p2 = static_cast<std::nullptr_t>(NULL);
    void(*f)(int) = NULL;
    int S::*mp = NULL;
    void(S::*mfp)(int) = NULL;
}


Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
CWG 903 C++11 constant expressions with zero value such as 1-1 were allowed only the literal zero is allowed

See also

nullptr the pointer literal which specifies a null pointer value (C++11)
(C++11)
the type of the null pointer literal nullptr
(typedef)