What is the definition of “array” in C?

ⅰ亾dé卋堺 提交于 2019-11-27 06:33:19

问题


The standard defines array type meticulously, but I don't see any definition for array.

We might say "object of array type", however that can't be right as untyped objects (e.g. space allocated by malloc) is described as an array.


Motivation: The specification for %s in fprintf (C11 7.21.6.1/8) says:

the argument shall be a pointer to the initial element of an array of character type

but take the code char s[] = "hello"; printf("%s", s+1); then we passed a pointer to the second element. That definition appears to be assuming that array means any set of contiguous object(s).


Edit: seeing as I have picked up some "unclear what you're asking" votes, my question is: What is that definition of the term array as used by ISO/IEC 9899:2011 ?


回答1:


Arrays are defined in the C Standard, 6.2.5, paragraph 20:

An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. 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’’. The construction of an array type from an element type is called ‘‘array type derivation’’.



来源:https://stackoverflow.com/questions/30546449/what-is-the-definition-of-array-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!