NULL与""空字符串的区别

""空字符串,会创建一个对象,分配内存空间

创新互联建站专注于浑南企业网站建设,响应式网站建设,商城网站制作。浑南网站建设公司,为浑南等地区提供建站服务。全流程按需网站制作,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

NULL,不会创建对象,不会分配内存空间,意思是不存在的

#include 
using namespace std;

int main()
{
        std::string strTemp;

        if( strTemp.empty() )
        {
                cout<<"is empty "<

在以下代码最后,用NULL与字符类型进行比较,会直接导致编译错误!

test.cpp:37:17: error: no match for ‘operator==’ in ‘strTemp == 0’

从编译的错误提示看:NULL为数值0

#include 
using namespace std;

int main()
{
        if( NULL == 0 )
        {
                cout<<"NULL is number 0"<(NULL)<

从这段代码,进一步验证了,NULL对就的值为数值0,地址为空

注意:将NULL赋值为int变量时会报警告

NULL.cpp:18:9: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]


网页名称:NULL与""空字符串的区别
文章位置:http://pwwzsj.com/article/jepjoi.html