int main(){
char *p1="china";
char p2[]="china";
char p3[100]={0};
strcpy(p3, "china");
cout << sizeof(p1) << endl;
cout << sizeof(p2) << endl;
cout << sizeof(p3) << endl;
cout << strlen(p1) << endl;
cout << strlen(p2) << endl;
cout << strlen(p3) << endl;
}
在vc上面的输出结果:
4
6
100
5
5
5
解释:sizeof(p1)是一个指针的大小;sizeof(p2)和sizeof(p3)是数组的大小,包括'\0',strlen则不包括结尾的'\0'。