![]() |
VOOZH | about |
In C++, NULL was traditionally used to represent null pointers. However, its use can lead to ambiguity in function overloading and unintended type conversions. To overcome these issues, C++11 introduced nullptr, a type-safe keyword that clearly represents a null pointer and eliminates ambiguity in pointer operations.
Output
cpp:20:8: error: call of overloaded 'fun(NULL)' is ambiguous
20 | fun(NULL);
Explanation
Replacing NULL with nullptr removes ambiguity because nullptr is a distinct pointer type.
fun(char*)
Unlike NULL, nullptr cannot be assigned to integer types.
Output
Compiler ErrorExplanation
nullptr can be used in conditions to check pointer validity.
false
Explanation: A null pointer evaluates to false in a conditional expression, while a valid pointer evaluates to true.
The nullptr keyword supports safe and well-defined comparisons with pointer types.
Output
can compare
x is null
Explanation