Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      NULL

      From cppreference.com
      <cpp‎ |types
       
       
      Utilities library
       
       
      Defined in header<clocale>
      Defined in header<cstddef>
      Defined in header<cstdio>
      Defined in header<cstdlib>
      Defined in header<cstring>
      Defined in header<ctime>
      Defined in header<cwchar>
      #define NULL /* implementation-defined */

      The macroNULL is an implementation-definednull pointer constant.

      Contents

      [edit]Possible implementation

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

      [edit]Notes

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

      [edit]Example

      Run this code
      #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'; ifconstexpr(std::is_same_v<decltype(NULL),std::nullptr_t>)std::cout<<"NULL implemented with type std::nullptr_t\n";elsestd::cout<<"NULL implemented using an integral type\n"; [](...){}(p, p2, f, mp, mfp);// < suppresses "unused variable" warnings}

      Possible output:

      The type of nullvar is longNULL implemented using an integral type

      [edit]See also

      nullptr(C++11) the pointer literal which specifies a null pointer value[edit]
      (C++11)
      the type of the null pointer literalnullptr
      (typedef)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/NULL&oldid=179240"

      [8]ページ先頭

      ©2009-2025 Movatter.jp