数组的大小及定义sizeof和strlen

来源:互联网 发布:龙泉驾校网络授课 编辑:程序博客网 时间:2024/05/21 04:16
char a[] = "abcd";char b[] = {'a','b','c','e','f'};int d = strlen(a);//4int e = strlen(b);//16cout << d << " " << e << endl;cout << a[2]<<" "<<b[2]<< endl;return 0;char st[20] = "hello\0\t\\"; int d = strlen(st);int f = sizeof(st);cout << d <<" "<<f<< endl;//d=5,只计算hello的长度,在结尾再次添加也没有用("hello\0\t\\qqq"),只是5,只有在前面添加有用,原因是\0,但是\0后面要是数字会变,为什么?.因为遇到\0就结束!//f=20,开辟的空间大小多少,就是多少,return 0;char st[20] = "hello\t\\";//7个char st[20] = "\77";//这个是\7后面的转为7进制?,不清楚,实验暂时得出\7后面如果不是数字\7算是1个字符,如果是,则\7加上后面挨着的数字算一个,大数会报错int d = strlen(st);//为1int f = sizeof(st);//20cout << d <<" "<<f<< endl;char st[20] = "89A\77";int d = strlen(st);//4int f = sizeof(st);char st[20] = "89A\t7";int d = strlen(st);//5int f = sizeof(st);strlen("asdasde\t\'\\wang\'!\t");//17每个\+后边的一个算一个,\\算一个,\a,算一个



0 0
原创粉丝点击