数组的大小及定义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\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);//为1
int f = sizeof(st);//20
cout << d <<" "<<f<< endl;

char st[20] = "89A\77";
int d = strlen(st);//4
int f = sizeof(st);

char st[20] = "89A\t7";
int d = strlen(st);//5
int f = sizeof(st);
strlen("asdasde\t\'\\wang\'!\t");//17每个\+后边的一个算一个,\\算一个,\a,算一个



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值