#include <iostream>
using namespace std;
int main()
{
char *p=NULL;
p="com\0hputer";
while(*p){
cout << *p;
p++;
}
return 0;
}
输出com
#include <iostream>
using namespace std;
int main()
{
char *p=NULL;
p="com0hputer";
while(*p){
cout << *p;
p++;
}
return 0;
}
输出 com0hputer
说明 字符串的0 其实是“0” 而不是 bool 的0
if('0'=="0")
{
cout<<"y";
}
error: ISO C++ forbids comparison between pointer and integer|
一个是char,一个是char * C++规定不能比较 C可以
本文通过两个C++示例程序演示了字符串处理中null终止符的影响,并解释了字符‘0’与布尔值0的区别及C++中比较指针与整数的限制。
1万+

被折叠的 条评论
为什么被折叠?



