Skip to content

Instantly share code, notes, and snippets.

@kangzhiheng
Created April 16, 2019 04:47
Show Gist options
  • Save kangzhiheng/834c601d01aff06f0899ace0cdafec4b to your computer and use it in GitHub Desktop.
Save kangzhiheng/834c601d01aff06f0899ace0cdafec4b to your computer and use it in GitHub Desktop.
关于NULL和nullptr
#include <iostream>
/*
关于NULL和nullptr
NULL ——> 宏定义为0(C++中, 在C中, NULL可以表示为空指针)
nullptr ——> 标识空指针,可以被转换成任意类型的指针和bool类型,但不能转换为整数。
*/
// 函数重载
void func(char*)
{
cout << "It's me!" << endl;
}
void func(int)
{
cout << "It's you!" << endl;
}
int main()
{
func(NULL); // 调用func(int) It's you!
func(nullptr); // 调用func(char*) It's me!
return 0;
}
@kangzhiheng
Copy link
Author

关于NULL和nullptr
NULL ——> 宏定义为0(C++中, 在C中, NULL可以表示为空指针)
nullptr ——> 标识空指针,可以被转换成任意类型的指针和bool类型,但不能转换为整数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment