一个简单sizeof的问题,希望不会难倒你!
huche 2004-08-07 10:41:35 我想大家都知道这两题的结果:
1.
char str1[] = "hello";
cout << sizeof(str1) << endl;
输出结果是:6
2.
char str2[5];
strcpy(str2, "hello");
cout << sizeof(str2) << endl;
输出结果是:5
但是,我查看了内存,实际上str1和str2都占了6个字节的内存,最后一个字节是0x00,为什么1和2的结果会不一样呢?