strlen和sizeof

来源:互联网 发布:各国域名缩写 编辑:程序博客网 时间:2024/06/05 08:41
#include<iostream>#include<string.h>using namespace std; int main(){char a[9] = "Hello";cout<<sizeof(a)<<" "<<strlen(a)<<endl; char b[] = "Hello";cout<<sizeof(b)<<" "<<strlen(b)<<endl;char *c = "Hello";cout<<sizeof(c)<<" "<<strlen(c)<<endl;return 0;} 

sizeof(c) 应该是指针的大小,应该和系统或编译器有关4或者8。

原创粉丝点击