简体   繁体   中英

Definition of array in c language

Definition of array is a collection of similar type of elements stored in adjacent locations.

Why is it not the collection of same elements stored in adjacent locations?

The authoritative quote, from the C11 standard:

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''.

Follow the emphasis (mine), it says about a (one) fixed type.

What you're expecting here, like

[...] collection of same elements [...]

may be misleading, as it may indicate that all the members has to be same type and value, which is not the case.

Rather, what is mentioned (whichever your source is)

similar type of elements

seems to do an appropriate job of conveying the actual stance.

TL;DR - All the member are of same type, the values can be same or different.

The same element means the same value, and that is not the right meaning.
A different way to say it would be: Definition of an array is a collection of elements *of the same type* stored in adjacent locations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM