c++ NULL、nullptr和数字0的区别

1、NULL、0和nullptr的区别

直接上源码
#include <iostream>
using namespace std;

void fun(int){
    cout << "hello \n";
}

void fun(void*){
    cout << "world \n";
}

int main(int argc, char *argv[])
{
    cout << "Hello World!" << endl;

    fun(0); //调用第一个函数
    fun(NULL); //调用第一个函数
    fun(nullptr); //调用第二个函数
    
    return 0;
}

Hello World!
hello 
hello 
world 


猜你喜欢

转载自blog.csdn.net/a119258/article/details/77162719