Predefined null pointer constant (since 哋它亢23)
Syntax
nullptr
|
(since 哋它亢23) | ||||||||
Explanation
The keyword nullptr
denotes a predefined null pointer constant. It is a MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 59 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE of type MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 58 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE. nullptr
can be MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 57 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE to a pointer types or bool, where the result is the null pointer value of that type or false respectively.
Keywords
Example
Demonstrates that a copy of nullptr
can also be used as a null pointer constant.
#include <stddef.h> #include <stdio.h> void g(int*) { MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 54 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE("Function g called"); } #define DETECT_NULL_POINTER_CONSTANT(e) \ _Generic(e, \ void* : puts("void*"), \ nullptr_t : puts("nullptr_t"), \ default : puts("integer") \ ) int main() { g(nullptr); // OK g(MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 53 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE); // OK g(0); // OK auto cloned_nullptr = nullptr; g(cloned_nullptr); // OK [[maybe_unused]] auto cloned_NULL = MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 52 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE; // g(cloned_NULL); // implementation-defined: maybe OK [[maybe_unused]] auto cloned_zero = 0; // g(cloned_zero); // Error DETECT_NULL_POINTER_CONSTANT(((void*)0)); DETECT_NULL_POINTER_CONSTANT(0); DETECT_NULL_POINTER_CONSTANT(nullptr); DETECT_NULL_POINTER_CONSTANT(MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 51 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE); // implementation-defined }
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 31 MINUTES 50 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
Function g called Function g called Function g called Function g called void* integer nullptr_t void*
See also
implementation-defined null pointer constant (macro constant) | |
(哋它亢23) |
the type of the predefined null pointer constant nullptr (typedef) |