C数组算术和指针 [英] C array arithmetic and pointers

查看:91
本文介绍了C数组算术和指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在C数组中为什么如此? a [5] == 5 [a]

Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]

我正在阅读有关C的教程,并且遇到了以下语法:

I am reading through a tutorial on C and I came across this syntax:

int doses[] = {1, 3, 2, 1000};
doses[3] == *(doses + 3) == *(3 + doses) == 3[doses]

现在的重点是获取int 1000,但是最后一个没有任何意义.它的迟到和我的大脑无法正常运行,或者是C特有的某种功能,或者是它的错字.关于指针,我想涵盖所有基本知识,因此请仔细阅读.这意味着要了解所有内容.任何答案将不胜感激!

Now the point is to get the int 1000, but the last one doesn't make any sense. Either its late and my brain is not functioning, its something specific to C, or its a typo. I want to cover all my basics when it comes to pointers so reading through it carefully. That means understanding it all. Any answers would be much appreciated!

推荐答案

来自维基百科

由于表达式a [i]在语义上等效于*(a + i),而表达式等价于*(i + a),因此表达式也可以写为i [a],尽管这种形式是很少使用.

Since the expression a[i] is semantically equivalent to *(a+i), which in turn is equivalent to *(i+a), the expression can also be written as i[a], although this form is rarely used.

这篇关于C数组算术和指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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