为什么这个片段可以用 C 编译?
3["zdvnngfgnfg"];
Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]
3["zdvnngfgnfg"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
3["zdvnngfgnfg"];
Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]
3["zdvnngfgnfg"];
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
它相当于
合法的,意思是“获取该文字的地址并向其添加
3*sizeof(char)
”。反正不会有什么影响。另请参阅这个非常相似的问题。
It's equivalent to
which is legal and means "take the address of that literal and add
3*sizeof(char)
to it". Will have no effect anyway.Also see this very similar question.
arr[i] 被解析为 *(arr+i) ,可以写为 *(i+arr) ,因此 i[arr]
现在“strngjwdgd”是一个指向存储在只读位置的常量字符数组的指针。
所以它有效!
arr[i] is parsed as *(arr+i) which can be written as *(i+arr) and hence i[arr]
Now "strngjwdgd" is a pointer to a constant character array stored at read only location.
so it works!!
字符串文字(
array
) 衰减为char*
类型的指针。然后取第四个元素:为什么可以在数组前面写下标又是一个问题:
在 C 数组中为什么会这样?
The string literal(
array
) decays to a pointer of typechar*
. Then you take the fourth element:Why you can write the subscript infront of the array is another question:
In C arrays why is this true?