全部博文(161)
分类: LINUX
2011-04-15 22:52:33
C/C++中'\0'作为字符串结束标志使用,具有唯一性,与'0'是有区别的。
在网络编程中的字符数组一般初始化为'\0'串,如:
char url[256] = {'\0'};
这样在对获取的字符串进行处理时就方便些。
测试程序:
#include
using namespace std;
int main()
{
char a = '0';
char b = '\0';
cout << a << "," << b << "," << boolalpha << (a==b) << endl;
//输出:0, ,false
int i = 0;
int j = '\0';
cout << i << "," << j << "," << boolalpha << (i==j) << endl;
//输出:0,0,true
return 0;
}