找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 284|回复: 1

Question6.10:I'm still mystified.Is a pointer a kind of array,or is an array is a kind of pointe

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-7-10 22:08:49 | 显示全部楼层 |阅读模式
Q: I'm still mystified.Is a pointer a kind of array, or is an array a kind of pointer?
A: An array is not a pointer, nor vice versa. An array reference (that is, any mention of an array in a value context), turns into a pointer (see
questions 6.2 and 6.3).
There are perhaps three ways to think about the situation:
       1、Pointers can simulate arrays (though that's not all; see question 4.1).
        2、There's hardly such a thing as an array (it is, after all, a ``second-class citizen''); the subscripting operator [] is in fact a pointer operator.
        3、At a higher level of abstraction, a pointer to a block of memory is effectively the same as an array (though this says nothing about other uses of
pointers).
But, to reiterate, here are two ways not to think about it:
        4、``They're completely the same.'' (False; see question 6.2.)
        5、 ``Arrays are constant pointers.'' (False; see question 6.9.)
See also question 6.8.

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-10 22:28:18 | 显示全部楼层
问题:我还在困惑,指针是不是一种数组或者说数值是一种指针?
回答:数组不是指针,相反的指针也不是数组。对于数组的引用(就是说在值的上下文中任何涉及到数组的)将会变成指针(参考问题6.2和6.3)。
将会有三种情形是正确的说法:
1、指针可以模拟数组(尽管这并不是全部,参考问题4.1)。
2、几乎没有一个叫做数组的东西(毕竟它是“二等公民”);实际上下标操纵付[]是一个指针操作符。
3、作为一个更高层次的抽象,指向一块内存的一个指针实际上和收一样(尽管这里没有说任何指针的用途)。
但是,重申一遍,这里的两种想法是不对的:
4、“它们是完全一样的”(错误的想法,参考问题6.2)。
5、“数组是常指针”(错误的想法,参考问题6.9)。
参考问题6.8。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 12:35 , Processed in 0.077891 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表