
C++,关于strlen函数
#include<iostream>#include<string.h>usingnamespacestd;intmain(){charb[122];b[0]='0';c...
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char b[122];
b[0]='0';
cout<<strlen(b)<<endl;
b[1]='1';
cout<<strlen(b)<<endl;
cout<<b<<endl;
return 0;
}
为什么第一个strlen为1,第二个为5,b为乱码 展开
#include <string.h>
using namespace std;
int main()
{
char b[122];
b[0]='0';
cout<<strlen(b)<<endl;
b[1]='1';
cout<<strlen(b)<<endl;
cout<<b<<endl;
return 0;
}
为什么第一个strlen为1,第二个为5,b为乱码 展开
3个回答
展开全部
乱码情况你的b[1]是结束符号,b[0]是字符,b[234]都是字符,b[6]是结束符号,所以你把一个结束符号修改为字符,他的strlen就增加了。一般不要对未初始化的数组进行操作。。。
追问
难道b[234]是随机被选成了字符??所以我错了?
追答
一个没有初始化的字符数组,里面每一个格子是什么东西都有可能的。
一开始这样写
char b[122]={0};
展开全部
原型:extern unsigned int strlen(char *s);,在Visual C++ 6.0中,原型 这个函数是用来求字符串长度的,直到\\0结束 ,yERnBF
满意请采纳。
满意请采纳。
追问
然后呢,不应该第一个为1,第二个为2吗?
还有为什么cout《b有乱码
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2016-04-16 · 知道合伙人教育行家
关注

展开全部
C++,关于strlen函数
cout<strlen(b)<
b[1]='.h><endl;<;b<
}
为什么第一个strlen为1;endl#include <<strlen(b)<endl;iostream>
cout<
using namespace std;string;
cout<
return 0;
#include <<
int main()
{
char b[122];0'
b[0]='<<;1',第二个为5
YCIPL?2014-5-24
b[6]是结束符号乱码情况你的b[1]是结束符号。一般不要对未初始化的数组进行操作,所以你把一个结束符号修改为字符。,b[0]是字符,他的strlen就增加了,b[234]都是字符。
cout<strlen(b)<
b[1]='.h><endl;<;b<
}
为什么第一个strlen为1;endl#include <<strlen(b)<endl;iostream>
cout<
using namespace std;string;
cout<
return 0;
#include <<
int main()
{
char b[122];0'
b[0]='<<;1',第二个为5
YCIPL?2014-5-24
b[6]是结束符号乱码情况你的b[1]是结束符号。一般不要对未初始化的数组进行操作,所以你把一个结束符号修改为字符。,b[0]是字符,他的strlen就增加了,b[234]都是字符。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询