sizeof 和strlen 的区别
c++吧
全部回复
仅看楼主
level 3
xiakeº 楼主
#include <iostream>
using namespace std;
void PrintSize(char* buffer)
{
cout << sizeof(buffer) << endl;
cout << strlen(buffer) << endl;
}
int main()
{
char buffer[10] = {'a', 'b', 'c', 'd', 'e'};
cout << sizeof(buffer) << endl;
PrintSize(buffer);
}
输出结果为10 4 5 第二个为什么为4
2016年04月20日 01点04分 1
level 11
指针4个字节
2016年04月20日 01点04分 2
非常感谢
2016年04月20日 02点04分
level 11
第三个为什么是5
2016年04月20日 15点04分 3
回复@sunny小麦Tracy :长度啊,五个西服
2016年04月20日 16点04分
1