为什么说char str[10]="string!"和char str[10]={"string!"};等价啊!这明明一个是字符数组一个字符串组
答案:3 悬赏:0 手机版
解决时间 2021-04-28 22:29
- 提问者网友:蓝莓格格巫
- 2021-04-28 07:32
为什么说char str[10]="string!"和char str[10]={"string!"};等价啊!这明明一个是字符数组一个字符串组
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-04-28 08:46
这两个是等价,不管是整体输出,或者是对某一项进行操作得到的结果是一样的!只是格式不同而已,第二种有点像二维数组初始化的感觉例如:
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++文件来测试一下,将里面的数字改成字符串,试试!
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++文件来测试一下,将里面的数字改成字符串,试试!
全部回答
- 1楼网友:孤独的牧羊人
- 2021-04-28 09:35
从右表达式看,你的理解一点都不错;可是一个一维字符串数组与字符数组形成的串有区别吗?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯