nullptr has type std::nullptr_t. It's implicitly convertible to any pointer type. Thus, it'll match std::nullptr_t or pointer types in overload resolution, but not other types such as int.
0 (aka. C's NULL bridged over into C++) could cause ambiguity in overloaded function resolution, among other things:
f(int);
f(foo *);
(Thanks to Caleth pointing this out in the comments.)
Answer from Joe Z on Stack Overflownullptr has type std::nullptr_t. It's implicitly convertible to any pointer type. Thus, it'll match std::nullptr_t or pointer types in overload resolution, but not other types such as int.
0 (aka. C's NULL bridged over into C++) could cause ambiguity in overloaded function resolution, among other things:
f(int);
f(foo *);
(Thanks to Caleth pointing this out in the comments.)
You can find a good explanation of why it was replaced by reading A name for the null pointer: nullptr, to quote the paper:
This problem falls into the following categories:
Improve support for library building, by providing a way for users to write less ambiguous code, so that over time library writers will not need to worry about overloading on integral and pointer types.
Improve support for generic programming, by making it easier to express both integer 0 and nullptr unambiguously.
Make C++ easier to teach and learn.
Is C NULL equal to C++11 nullptr - Stack Overflow
[C++] Difference between null and nullptr
NULL Define in c & c++ differs?! | Handmade Network
c++ - Should I cast comparisons to NULL or nullptr? - Software Engineering Stack Exchange
Videos
Flocked straight here because the toxic stack overflow has the biggest trigger finger when it comes to marking posts as duplicates.
But anywho.
I had an examination recently, and I remember one of the theory questions asking what the difference is between null and nullptr in c++. I was unsure and didn't know how to answer it, for future reference could someone please explain to me what differs between the two.