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 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章