What is nullptr?

One of the reasons to use nullptr in c++11 is https://www.zhihu.com/question/55936870.

A simple demo of the comparison between nullptr, 0, and (void*)0.

// nullptr
#include <iostream>

using namespace std;

int main()
{
	void * p1 = 0;
	int p2 = 0;
	
//	if(p1 == p2)
//		cout << "1" << endl;
	if(p1 == nullptr)
		cout << "(void*)0 == nullptr" << endl;
//	if(p2 == nullptr)
//		cout << "0 == nullptr" << endl;
			
	return 0;
}
posted @ 2017-02-23 11:18  ch3cooh  阅读(192)  评论(0)    收藏  举报

Too young too simple. Sometimes naive! -- Quote from the elderly.