设为首页 加入收藏

TOP

数组和指针背后――内存角度 (二)
2014-11-24 00:33:10 来源: 作者: 【 】 浏览:62
Tags:指针 背后 内存 角度
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

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇堆栈,堆栈,堆和栈的区别 下一篇我的C/C++之路-011课(读取文件)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: