asuerhao's Blog

如果有什么做的不到的地方请尽管留言, 我会改进的 : )

C 数组下标'[ ]'运算符

asuerhao posted @ 2012年4月16日 21:09 in 积累 with tags c 数组 , 1709 阅读

  C语言是通过数组下标来引用数组的, 我们这样定义一个有十个元素的整型数组:

int arr[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

  然后可以通过数组arr的下标对其元素进行引用:

a[0] = a[1]+a[2];

  实际上, 数组下标'[ ]'是一种运算符, 程序中用下标法引用数组元素的代码, 最终都被编译器自动转化为指针进行运算, 也就是说, 'a[i]'和'*(a+i)'在编译器看来, 是完全等价的.
  由此, 可以理解以下代码:

#include<stdio.h>
int main(void)
{
	struct hi {
		int a;
		int b;
	};
	struct hi test;
	test.a=1;
	test.b=2;
	printf("%d, %d\n", test.a, test.b);
	/* 真正写代码时, 请不要这样用: */
	printf("%d, %d\n", ((int*)(&test))[0], ((int*)(&test))[1]);
	return 0;
}

  打印结果为:
1, 2
1, 2

Avatar_small
deep cleaning servic 说:
2021年8月30日 19:55

Presently in need of a solid office cleaning plumber in Dubai? Should yes, then we only at Crystal Form of transport are a ever-present other half. We strive to use the hottest cleaning machinery to take out all stubborn stains on your office. We understand the value of that has a clean clinic. It gets better your belief, not to mention that some clean work place improves work productivity. We itinerary an clinic cleaning schedule dependant upon your selections. You can inform us with the needs, and we will take it again from furthermore there. Besides, our tailor made offices vacuuming services provide us in order to satisfy your specific cleaning preferences.

Avatar_small
part time maids in d 说:
2021年11月15日 23:18

Normally maids will be remembered only whilst house cleaning up service and also for cleaning up upholstery and also backyard cleaning up. But there is any dwelling renovation deliver the results done, to clean up up a mess service personnel role comes into play quite invaluable. No topic how excited will probably be about the fresh renovations in your own home, it's hard to live excited while you see a mess that is definitely left at home.

Avatar_small
maid services dubai 说:
2023年10月06日 20:03

The place becomes unclean and in a mess but everyone ignore the software because everyone just are deprived of the effort! And it's always in cases like all of these that we want to be make a fabulous wish "It could possibly have been for that reason nice if we a maid or even cleaning company that could address our home for american.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter