知识分为两部分,一部分记在脑子里,一部分记在博客上 ^_^
strlen 不包括最后的结束符 '\0'
int _tmain(int argc, _TCHAR* argv[])
{
const char* szName = "fuck";
const char* szNULL = "";
char array[] = {0};
char name[] = "bitch";
const char* szChineseName = "北京号";
unsigned int IntArray[30] = {0};
char blankName[32] = "";
std::cout << "strlen(szName): " << strlen(szName) << "\n"
<< "strlen(szNULL): " << strlen(szNULL) << "\n"
<< "sizeof(szName): " << sizeof(szName) << "\n"
<< "sizeof(szNULL): " << sizeof(szNULL) << "\n"
<< "strlen(array): " << strlen(array) << "\n"
<< "strlen(name): " << strlen(name) << "\n"
<< "sizeof(array): " << sizeof(array) << "\n"
<< "sizeof(name): " << sizeof(name) << "\n"
<< "strlen(szChineseName): "<< strlen(szChineseName) << "\n"
<< "sizeof(IntArray): " << sizeof(IntArray) << "\n"
<< "strlen(blankName)" << strlen(blankName) << "\n"
<< "sizeof(blankName)" << sizeof(blankName) << "\n"
<< std::endl;
return 0;
}
输出:
strlen(szName): 4
strlen(szNULL): 0
sizeof(szName): 4
sizeof(szNULL): 4
strlen(array): 0
strlen(name): 5
sizeof(array): 1
sizeof(name): 6
strlen(szChineseName): 6
sizeof(IntArray): 120
strlen(blankName)0
sizeof(blankName)32
请按任意键继续. . .
2011-02-16 这么多年过去了哈!容易忘记是理解不深刻!看完林锐博士的《高质量程序设计指南》7.3字符数组、字符指针和字符串后,就不会搞错了!
posted on 2007-08-05 01:05
七星重剑 阅读(291)
评论(2) 编辑 收藏 引用 所属分类:
PL--c/c++