C 多维数组中奇怪的数组语法
我知道这是真的:
x[4] == 4[x]
多维数组的等效项是什么?以下内容是否属实?
x[4][3] == 3[x[4]] == 3[4[x]]
I've known that this is true:
x[4] == 4[x]
What is the equivalent for multi-dimensional arrays? Is the following true?
x[4][3] == 3[x[4]] == 3[4[x]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
x[y]
定义为*(x + (y))
x[y][z]
将变为*( *(x + (y)) + z)
x[y[z]]
将变为*(x + (*(y + (z))))< /code>
x[4][3]
将变为*(*(x + (4)) + 3)
将变为
*(*(x + 4) + 3)
3[x[4]]
将变为*(3 + (*(x + (4))))
将变为*(* (x + 4) + 3)
3[4[x]]
将变为*(3 + (*(4 + (x))))
将变为*(*(x + 4 ) + 3)
这意味着它们都是等价的。
x[y]
is defined as*(x + (y))
x[y][z]
would become*(*(x + (y)) + z)
x[y[z]]
would become*(x + (*(y + (z))))
x[4][3]
would become*(*(x + (4)) + 3)
would become
*(*(x + 4) + 3)
3[x[4]]
would become*(3 + (*(x + (4))))
would become*(*(x + 4) + 3)
3[4[x]]
would become*(3 + (*(4 + (x))))
would become*(*(x + 4) + 3)
Which means they are all equivalent.
是的。在每种情况下,x 都是一个数组,它会衰减为指针,然后对其执行指针算术。
Yes. In each case
x
is an array which decays to a pointer and then has pointer arithmetic performed on it.