数组和指针背后――内存角度 (二)

2014-11-24 00:33:10 · 作者: · 浏览: 75
ion) is always changed, by the compiler, to a pointer to the start of the array.
4. Therefore, you have the choice for defining a function parameter which is an array,
either as an array or as a pointer. Whichever way you define it, you actually get a
pointer inside the function.
5. In all other cases, definitions should match declarations. If you defined it as an array,
your extern declaration should be an array. And likewise for a pointer.

1)对于a [i]这种形式的访问数组,通常被解释为指针形式*(a + i) 也就是上文中所说的“表达式”的情形

2)指针就是指针,没有说指针转化为数组的情况,你可以用下标的形式去访问指针,但一般都是指针作为函数参数时,而且传入的是一个数组

3)在函数参数的声明中,数组可以看做指针,(也只有这种情况)

4)当把一个数组定义为函数参数时,可以定义为数组,也可以是指针

5)其他的所有情况,声明和定义必须匹配。如果定义了一个数组,在其他文件中对它也必须声明为数组。指针也一样。

参考资料:《expert c programming》

如转载请注明出处:http://www.cnblogs.com/yanlingyin/

一条鱼@博客园

2011-12-6