有没有使用[i]和*(A + I)之间的区别吗? [英] Is there a difference between using a[i] and *(a + i)?

查看:89
本文介绍了有没有使用[i]和*(A + I)之间的区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者 A [I] *(A + I)访问个数组元素 A

Both a[i] and *(a + i) access the i th element of array a.

有没有理由preFER一个比其他(性能,可读性等等... 的)?

Are there reasons to prefer one over the other(performance, readability, etc...)?

推荐答案

无论一个是从一个语言点更好,因为它们是相同的,数组下标应该仅仅是为指针运算语法糖。我们可以从 C99标准草稿看到这部分 6.5.2.1 数组下标的它说(的重点煤矿的):

Neither one is better from a language point of view since they are the same, array indexing should just be syntactic sugar for pointer arithmetic. We can see this from the draft C99 standard section 6.5.2.1 Array subscripting which says (emphasis mine):

[...]下标运算符[]的定义是,E1 [E2]是的相同以(*((E1)+(E2)))。[...]

[...]The definition of the subscript operator [] is that E1[E2] is identical to (*((E1)+(E2))).[..]

虽然别人读你的code A [I] 可能是更具可读性。

Although for others reading your code a[i] is probably more readable.

这篇关于有没有使用[i]和*(A + I)之间的区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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