为什么说char str[10]="string!"和char str[10]={"string!"};等价啊!这明明一个是字符数组一个字符串组
3个回答
展开全部
这两个是等价,不管是整体输出,或者是对某一项进行操作得到的结果是一样的!只是格式不同而已,第二种有点像二维数组初始化的感觉例如:
string sz[5][5]={ {"1","2 ","3,"4 ","5 "},
{" 1","2","3 ","4","5 " },
{" 1","2","3 ","4","5 " },
{" 1","2","3 ","4","5 " },
{" 1","2","3 ","4","5 " }}
string sz[5][5]={ {"1","2 ","3,"4 ","5 "},
{" 1","2","3 ","4","5 " },
{" 1","2","3 ","4","5 " },
{" 1","2","3 ","4","5 " },
{" 1","2","3 ","4","5 " }}
追问
没懂你的意思啊?我的问题主要是字符串数组为啥能和字符数组等价。有个哥们说当字符串数组为一维时就和字符串等价了,也就是和字符数组等价了,你说对不
追答
是啊,我给你的就是二维字符串数组,你可以使用一个c++文件来测试一下,将里面的数字改成字符串,试试!
展开全部
从右表达式看,你的理解一点都不错;可是一个一维字符串数组与字符数组形成的串有区别吗?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
char是字符数组,string才是字符串数组,你写的有问题吧?
更多追问追答
追问
我看到 书上说char str[10]="string!"和char str[10]={"string!"};等价,可我觉得不等价啊?前者是字符数组,后者是字符串数组啊?这怎么可能等价呢
追答
字符是以''两个单引号括起来的,字符是“”两个双引号括起来的,明白了吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询