• 5528阅读
  • 1回复

Question6.10:I'm still mystified.Is a pointer a kind of array,or is an array is a kind of pointe [复制链接]

上一主题 下一主题
离线那个谁
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2013-07-10
— 本帖被 tyrone2497谁 执行加亮操作(2013-07-19) —
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.
离线那个谁

只看该作者 沙发  发表于: 2013-07-10
问题:我还在困惑,指针是不是一种数组或者说数值是一种指针?
回答:数组不是指针,相反的指针也不是数组。对于数组的引用(就是说在值的上下文中任何涉及到数组的)将会变成指针(参考问题6.2和6.3)。
将会有三种情形是正确的说法:
1、指针可以模拟数组(尽管这并不是全部,参考问题4.1)。
2、几乎没有一个叫做数组的东西(毕竟它是“二等公民”);实际上下标操纵付[]是一个指针操作符。
3、作为一个更高层次的抽象,指向一块内存的一个指针实际上和收一样(尽管这里没有说任何指针的用途)。
但是,重申一遍,这里的两种想法是不对的:
4、“它们是完全一样的”(错误的想法,参考问题6.2)。
5、“数组是常指针”(错误的想法,参考问题6.9)。
参考问题6.8。
快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个