访问数组内容:x [n] vs n [x] [英] Accessing array contents: x[n] vs n[x]

查看:212
本文介绍了访问数组内容:x [n] vs n [x]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

通过C和C ++中的索引[array]访问数组


我最近发现了一些我从来没有见过的在C(和C + +)中访问数组的内容,你可以使用 x [n] n [x]



3 [x]



相同所以我的第一个问题是这个工作,有什么使用第二个语法是有用的(除了让我困惑)。

解决方案

x [n] *(x + n)



p>

n [x] *(n + x)



,所以表达式是等效的。使用第二个没有什么好处。


Possible Duplicate:
Accessing arrays by index[array] in C and C++

I have recently found out something that I had never seen before in C (and C++) in that for accessing the contents of an array you can use x[n] or n[x]

So for example x[3] is the same as 3[x]

So my first question is how does this work and is there anything using the 2nd syntax that is useful (apart from confusing me)?

解决方案

x[n] is *(x + n)

and

n[x] is *(n + x)

so the expressions are equivalent. There is nothing beneficial in using the second.

这篇关于访问数组内容:x [n] vs n [x]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆