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 


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