iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
An array of structures stores multiple records of the same structure type. Each array element is one record, and you select a field by combining its index with the field name—for example, points[0].x accesses the x member of the first point.
What is an array of structures?
An array of structures is an array whose element type is a structure. Every element has the same structure members, so the array holds a sequence of records with a consistent set of fields. The GNU C Reference Manual explains that a structure type can be used to create an array just like a primitive data type: GNU C Reference Manual: Arrays of Structures.
How do you declare and initialize one in C?
First define a structure type, then declare an array using that type. This C example creates three points and gives each one an x and y coordinate:
struct point {
int x;
int y;
};
struct point points[3] = {{2, 3}, {4, 5}, {6, 7}};
The declaration struct point points[3] means that points contains three elements, each of type struct point. The nested braces initialize the fields of each element in the order they appear in the structure definition.
#1 Best Overall
How do you access a structure in the array?
Use an array index to select an element, then use the dot operator and a member name to select one of its fields:
int first_x = points[0].x;
int third_y = points[2].y;
In points[0].x, the index 0 selects the first structure and .x selects its x member. C array indexing starts at zero, so the three elements in this example are indexed 0, 1, and 2.
How does an array of structures differ from a structure of arrays?
An array of structures (AoS) groups fields together by record. A structure of arrays (SoA) instead groups values by field. Which organization is more suitable depends on what the program does with the data:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors| Layout | Organization | Often a natural fit when |
|---|---|---|
| Array of structures (AoS) | Each element contains a complete record, such as one point’s x and y. |
An operation usually needs several fields from each record. |
| Structure of arrays (SoA) | Each field has its own collection, such as one array of x values and another of y values. |
An operation usually processes one field across many records. |
These are workload-based guidelines, not performance guarantees. If layout matters for speed, profile the actual program and workload rather than assuming one arrangement is always faster.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What should you know about memory layout?
Array elements are stored as structure values, and a compiler accounts for each structure’s size when locating the next element. A structure may include padding between or after members to meet implementation requirements. Consequently, do not assume a particular structure size or member offset unless it is established for the applicable implementation and declarations. The GNU C Reference Manual discusses arrays of structures and their member access: GNU C Reference Manual: Arrays of Structures.
The syntax shown here is C syntax. The term “array of structures” describes a general data organization, but declarations and array sizing rules vary by programming language.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

