Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c#

null

nullptr

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

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

like image 591
whiteSkar Avatar asked Mar 21 '14 05:03

whiteSkar


People also ask

Is null and nullptr same?

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.

Can null and nullptr be used interchangeably?

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.

What is the value of nullptr?

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.

What is nullptr in C language?

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.


1 Answers

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.

like image 103
Michael Aaron Safyan Avatar answered Sep 18 '22 20:09

Michael Aaron Safyan