📜  C语言中结构与数组之间的区别

📅  最后修改于: 2021-05-25 22:33:21             🧑  作者: Mango

C中的数组

数组是存储在连续内存位置中的项目的集合。
数组

C语言的结构

结构是C / C++中用户定义的数据类型。结构创建一个数据类型,该数据类型可用于将可能不同类型的项目分组为单个类型。

结构和数组之间的区别

ARRAY STRUCTURE
Array refers to a collection consisting of elements of homogenous data type. Structure refers to a collection consisting of elements of heterogenous data type.
Array uses subscripts or “[ ]” (square bracket) for element access Structure uses “.” (Dot operator) for element access
Array is pointer as it points to the first element of the collection. Structure is not a pointer
Instantiation of Array objects is not possible. Instantiation of Structure objects is possible.
Array size is fixed and is basically the number of elements multiplied by the size of an element. Structure size is not fixed as each element of Structure can be of different type and size.
Bit filed is not possible in an Array. Bit filed is possible in an Structure.
Array declaration is done simply using [] and not any keyword. Structure declaration is done with the help of “struct” keyword.
Arrays is a primitive datatype Structure is a user-defined datatype.
Array traversal and searching is easy and fast. Structure traversal and searching is complex and slow.
data_type array_name[size]; struct sruct_name{
data_type1 ele1;
data_type2 ele2;
};
Array elements are stored in continuous memory locations. Structure elements may or may not be stored in a continuous memory location.
Array elements are accessed by their index number using subscripts. Structure elements are accessed by their names using dot operator.
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。