A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../error/error_code/../../../cpp/types/NULL.html below:

NULL - cppreference.com

#define NULL /* implementation-defined */

The macro NULL is an implementation-defined null pointer constant.

[edit] Possible implementation
#define NULL 0
// since C++11
#define NULL nullptr
[edit] Notes

In C, the macro NULL may have the type void*, but that is not allowed in C++ because null pointer constants cannot have that type.

[edit] Example
#include <cstddef>
#include <iostream>
#include <type_traits>
#include <typeinfo>
 
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;
    auto nullvar = NULL; // may trigger a warning when compiling with gcc/clang
 
    std::cout << "The type of nullvar is " << typeid(nullvar).name() << '\n';
 
    if constexpr(std::is_same_v<decltype(NULL), std::nullptr_t>)
        std::cout << "NULL implemented with type std::nullptr_t\n";
    else
        std::cout << "NULL implemented using an integral type\n";
 
    [](...){}(p, p2, f, mp, mfp); // < suppresses "unused variable" warnings
}

Possible output:

The type of nullvar is long
NULL implemented using an integral type
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4