Menu
Nullptr A C programmer frequently come across pointer variables, pointer arguments to function and pointer template arguments. Let us take different cases to see how C98 handles the situation where a pointer is set to nothing. C used to lack a special value to indicate a null pointer, which led to some problems. The new standard introduces a new reserved word nullptr, to designate a constant rvalue that represents a null pointer. Read on to learn more.
< cpp | language
C++Language | ||||
Standard Library Headers | ||||
Freestanding and hosted implementations | ||||
Named requirements | ||||
Language support library | ||||
Concepts library(C++20) | ||||
Diagnostics library | ||||
Utilities library | ||||
Strings library | ||||
Containers library | ||||
Iterators library | ||||
Ranges library(C++20) | ||||
Algorithms library | ||||
Numerics library | ||||
Input/output library | ||||
Localizations library | ||||
Regular expressions library(C++11) | ||||
Atomic operations library(C++11) | ||||
Thread support library(C++11) | ||||
Filesystem library(C++17) | ||||
Technical Specifications |
I am running Eclipse Helios and I have g-4.6 installed. Hope I am not wrong that g4.6 implements C 11 features. I have created a C project which uses the nullptr and auto keywords. Nov 13, 2017 This video is about null and nullptr in c and how we use them. Please subscribe the channel.
General topics | ||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||
Flow control | ||||||||||||||||||||||||||||||||||||||||||||||
Conditional execution statements | ||||||||||||||||||||||||||||||||||||||||||||||
Iteration statements (loops) | ||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||
Jump statements | ||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||
Functions | ||||||||||||||||||||||||||||||||||||||||||||||
Function declaration | ||||||||||||||||||||||||||||||||||||||||||||||
Lambda function declaration | ||||||||||||||||||||||||||||||||||||||||||||||
inline specifier | ||||||||||||||||||||||||||||||||||||||||||||||
Exception specifications(until C++20) | ||||||||||||||||||||||||||||||||||||||||||||||
noexcept specifier(C++11) | ||||||||||||||||||||||||||||||||||||||||||||||
Exceptions | ||||||||||||||||||||||||||||||||||||||||||||||
Namespaces | ||||||||||||||||||||||||||||||||||||||||||||||
Types | ||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||
Specifiers | ||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||
Storage duration specifiers | ||||||||||||||||||||||||||||||||||||||||||||||
Initialization | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
Expressions | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
Alternative representations | |||||||||||||||||||||||||||||||
Literals | |||||||||||||||||||||||||||||||
Boolean - Integer - Floating-point | |||||||||||||||||||||||||||||||
Character - String - nullptr (C++11) | |||||||||||||||||||||||||||||||
User-defined(C++11) | |||||||||||||||||||||||||||||||
Utilities | |||||||||||||||||||||||||||||||
Attributes(C++11) | |||||||||||||||||||||||||||||||
Types | |||||||||||||||||||||||||||||||
typedef declaration | |||||||||||||||||||||||||||||||
Type alias declaration(C++11) | |||||||||||||||||||||||||||||||
Casts | |||||||||||||||||||||||||||||||
Implicit conversions - Explicit conversions | |||||||||||||||||||||||||||||||
static_cast - dynamic_cast | |||||||||||||||||||||||||||||||
const_cast - reinterpret_cast | |||||||||||||||||||||||||||||||
Memory allocation | |||||||||||||||||||||||||||||||
Classes | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
Class-specific function properties | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
Special member functions | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Templates | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
Miscellaneous |
General | ||||
value categories (lvalue, rvalue, xvalue) | ||||
order of evaluation (sequence points) | ||||
constant expressions | ||||
unevaluated expressions | ||||
primary expressions | ||||
lambda-expression(C++11) | ||||
Literals | ||||
integer literals | ||||
floating-point literals | ||||
boolean literals | ||||
character literals including escape sequences | ||||
string literals | ||||
null pointer literal(C++11) | ||||
user-defined literal(C++11) | ||||
Operators | ||||
Assignment operators: a=b , a+=b , a-=b , a*=b , a/=b , a%=b , a&=b , a|=b , a^=b , a<<=b , a>>=b | ||||
Increment and decrement: ++a , --a , a++ , a-- | ||||
Arithmetic operators:+a , -a , a+b , a-b , a*b , a/b , a%b , ~a , a&b , a|b , a^b , a<<b , a>>b | ||||
Logical operators: a||b , a&&b , !a | ||||
Comparison operators: ab , a!=b , a<b , a>b , a<=b , a>=b , a<=>b (C++20) | ||||
Member access operators: a[b] , *a , &a , a->b , a.b , a->*b , a.*b | ||||
Other operators: a(...) , a,b , a?b:c | ||||
Default comparisons(C++20) | ||||
Alternative representations of operators | ||||
Precedence and associativity | ||||
Fold expression(C++17) | ||||
new-expression | ||||
delete-expression | ||||
throw-expression | ||||
alignof | ||||
sizeof | ||||
sizeof...(C++11) | ||||
typeid | ||||
noexcept(C++11) | ||||
Operator overloading | ||||
Conversions | ||||
Implicit conversions | ||||
const_cast | ||||
static_cast | ||||
reinterpret_cast | ||||
dynamic_cast | ||||
Explicit conversions(T)a , T(a) | ||||
User-defined conversion |
[edit]Syntax
nullptr | (since C++11) |
[edit]Explanation
The keyword
nullptr
denotes the pointer literal. It is a prvalue of type std::nullptr_t. There exist implicit conversions from nullptr
to null pointer value of any pointer type and any pointer to member type. Similar conversions exist for any null pointer constant, which includes values of type std::nullptr_t as well as the macro NULL.[edit]Example
Demonstrates that
nullptr
retains the meaning of null pointer constant even if it is no longer a literal.Output:
[edit]Keywords
[edit]References
- C++17 standard (ISO/IEC 14882:2017):
- 7.11 Pointer conversions [conv.ptr]
Dev C++ Online
- C++14 standard (ISO/IEC 14882:2014):
- 4.10 Pointer conversions [conv.ptr]
C++ Nullptr Library
- C++11 standard (ISO/IEC 14882:2011):
Nullptr Dev C++
- 4.10 Pointer conversions [conv.ptr]
[edit]See also
Nullptr In Dev C 2017
implementation-defined null pointer constant (macro constant)[edit] | |
(C++11) | the type of the null pointer literal nullptr (typedef)[edit] |
Retrieved from 'https://en.cppreference.com/mwiki/index.php?title=cpp/language/nullptr&oldid=117353'