sizeof strlen区别

来源:互联网 发布:mac清理系统占用空间 编辑:程序博客网 时间:2024/05/16 12:27

sizeof() 关键字,编译期确定结果

strlen()函数,运行期确定结果,字符串长度

如:char name[12] = {"hello world"};

sizeof(name) = 12;数组长度

strlen(name) = 11,字符串长度


name[5] = 0;

sizeof(name) = 12;数组长度

strlen(name) = 5,字符串长度


cout << name结果为hello

cout认为遇到\0就结束


0 0
原创粉丝点击