c - c语言数组的定义

标签 c arrays

数组的定义是存储在相邻位置的相似类型元素的集合。

为什么不是相邻位置存储相同元素的集合?

最佳答案

权威引用,来自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/

相关文章:

java - 如何添加到main中的数组?

C 字符串使用索引或指针复制字符

c - 尝试将内存分配给单独声明的指针变量时出错

c - 如何在 ubuntu 中安装 dos.h

c - 为什么余数不适用于 Float 值?

php - 将字符串拆分为日期数组

c - SDL_Mixer 设置声音位置

c++ - 返回 char* 形式的 C++ 函数

javascript - 从多维数组中删除重复项

c++ - 在 C++ 中连接 char 数组(棘手)