Is nullptr in C++ the same as null in C#?
Seems like no one asked this question on Google or Stackflow.
nullptr is a keyword that can be used at all places where NULL is expected. Like NULL, nullptr is implicitly convertible and comparable to any pointer type. Unlike NULL, it is not implicitly convertible or comparable to integral types.
In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days. If you have to name the null pointer, call it nullptr; that's what it's called in C++11.
The nullptr keyword represents a null pointer value. Use a null pointer value to indicate that an object handle, interior pointer, or native pointer type does not point to an object.
A null pointer is a pointer which points nothing. Some uses of the null pointer are: a) To initialize a pointer variable when that pointer variable isn't assigned any valid memory address yet. b) To pass a null pointer to a function argument when we don't want to pass any valid memory address.
Yes. In C++, nullptr
is the equivalent of null
in Java, C#, and a variety of other languages. Prior to C++11, it was standard to use NULL
(which was a macro defined as 0); however, nullptr
actually ensures that it can be used only in the context of pointers (whereas NULL
, by virtue of having been defined as 0, can also be used as the return value for a function that returns an int
instead of a pointer, which is counterintuitive), though both nullptr
and NULL
are implicitly convertible to bool
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With