05NULL和nullptr的区别

image

int main()
{
	char* p = NULL;// = 0
	char* q = nullptr;//只能是指针
	int* a = nullptr;
	//int a = nullptr;//canot
	int b = NULL;// = 0
	if (p == nullptr) {
		cout << "good" << endl;
	}
	if (q == NULL) {
		cout << "good" << endl;
	}
	//引入nullptr的目的是为了,避免整型和指针的混淆
	cout << typeid(NULL).name() << endl;//int 
	cout << typeid(nullptr).name() << endl;//std::nullprt_t
	return 0;
}
posted @ 2022-03-13 12:35  豪崽_ZH  阅读(54)  评论(0)    收藏  举报