Domanda

Is nullptr in C++ the same as null in C#?

Seems like no one asked this question on Google or Stackflow.

È stato utile?

Soluzione

In general yes, both assign the null value to pointer like types

  • C#: class, interface, delegate or pointer types
  • C++: pointer types or pointer-to-member type

It doesn't convert to numeric values in either language. One difference though is that in C++ nullptr can convert to bool. This is not true in C#

Altri suggerimenti

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.

Yes, it is the same. It is the invalid pointer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top