数组的大小及定义sizeof和strlen
char a[] = "abcd"; char b[] = {"a","b","c","e","f"}; int d = strlen(a);//4 int e = strlen(b);//16 cout << d << " " << e << endl; cout << a[2]<<" "<<b[2]<< endl; return 0; char st[20] = "hello \"; int d = strlen(st); int f = sizeof(st); cout << d <<" "<<f<< endl;//d=5,只计算hello的长度,在结尾再次添加也没有用("hello \qqq"),只是5,只有在前面添加有用,原因是 ,但是 后面要是数字会变,为什么?.因为遇到 就结束! //f=20,开辟的空间大小多少,就是多少, return 0; char st[20] = "hello \";//7个 char st[20] = "77";//这个是7后面的转为7进制?,不清楚,实验暂时得出7后面如果不是数字7算是1个字符,如果是,则7加上后面挨着的数字算一个,大数会报错 int d = strlen(st);//为1 int f = sizeof(st);//20 cout << d <<" "<<f<< endl; char st[20] = "89A77"; int d = strlen(st);//4 int f = sizeof(st); char st[20] = "89A 7"; int d = strlen(st);//5 int f = sizeof(st); strlen("asdasde "\wang"! ");//17每个+后边的一个算一个,\算一个,a,算一个
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: 数组中插入元素(C++)