nullptr in C++

In C++11 and later versions, we can now use a proper null pointer value. It is named as nullptr and is a C++ keyword. Unlike 0 or NULL which were an integer and a pointer to void respectively, nullptr is cleaner and brings in stronger type checking. nullptr can be assigned to any pointer variable.

I could not find the definition of nullptr, I guess it is defined inside the compiler itself. The closest I could find is nullptr_t, which is the type of nullptr. For GCC 4.9, I found that this is defined in /usr/include/x86_64-linux-gnu/c++/4.9/bits/c++config.h:

typedef decltype(nullptr) nullptr_t;

Tried with: GCC 4.9.1 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s