C++11中的nullptr和NULL的区别

代码:

#include <iostream>

using namespace std;

void foo(long long  num) {
    cout << "This is long long parameter" << endl;
}


void foo(int * num) {
    cout << "This is point parameter" << endl;
}


int main() {
    foo(NULL);
    foo(nullptr);
}

输出结果:

This is long long parameter
This is point parameter

进入NULL的定义处

#define NULL 0LL

从上面的输出结果来看,很明显NULL的值目前为long long类型的0值,而nullptr才是真正意义上的空指针。

发布了39 篇原创文章 · 获赞 9 · 访问量 1948

猜你喜欢

转载自blog.csdn.net/qq_36296888/article/details/103532981