数组的定义是存储在相邻位置的相似类型元素的集合。
为什么不是相邻位置存储相同元素的集合?
最佳答案
权威引用,来自C11
标准:
An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. The element type shall be complete whenever the array type is specified. Array types are characterized by their element type and by the number of elements in the array. An array type is said to be derived from its element type, and if its element type is T, the array type is sometimes called ‘‘array of T’’.
按照强调(我的),它说的是(一个)固定类型。
你在这里期待什么,比如
[...] collection of same elements [...]
可能会产生误导,因为它可能表明所有成员都必须具有相同的类型和值,但事实并非如此。
而是提到的内容(无论您的来源是什么)
similar type of elements
似乎在传达实际立场方面做了适当的工作。
TL;DR - 所有成员都是同一类型,值可以相同或不同。
关于c - c语言数组的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51260836/