Recommended Free Tools
An array of structures is an array whose elements are all values of the same structure type. Each element represents one record with the fields declared in that structure; an index chooses the record, and a member name chooses a field within it.
What an array of structures means
A structure type groups related members, such as an x coordinate and a y coordinate. An array of that type stores multiple structure values in an indexed sequence. In C, the array element type is the structure type, so every element has the same declared set of members.
As an Amazon Associate I earn from qualifying purchases.
The GNU C Reference Manual describes the basic idea: “You can create an array of a structure type just as you can an array of a primitive data type.”
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →How to declare, initialize, and access one in C
Here is a complete example:
struct point {
int x;
int y;
};
struct point points[3] = {{2, 3}, {4, 5}, {6, 7}};
int first_x = points[0].x;
points contains three struct point values. The initializer fills their members in declaration order: the first point has x equal to 2 and y equal to 3, for example. The expression points[0] selects the first structure, and .x selects that structure’s x member.
#1 Best Overall
- Define the structure type, as
struct pointis defined above. - Declare an array with that type and a size, such as
struct point points[3];. - Optionally initialize its elements with aggregate initializers, such as
{{2, 3}, {4, 5}, {6, 7}}. - Select a record with an index and its field with the member operator:
points[0].x.
This declaration and syntax are specific to C; other languages use their own syntax and may have different array-sizing rules.
How an array of structures differs from a structure of arrays
These layouts organize the same kinds of data differently. An array of structures (AoS) groups fields by record; a structure of arrays (SoA) groups values by field.
Rank #2
| Layout | Organization | Often a useful fit |
|---|---|---|
| Array of structures (AoS) | Each array element contains one record and its fields. | Operations that commonly need several fields from each record. |
| Structure of arrays (SoA) | Separate arrays hold values for each field. | Operations that commonly process one field across many records. |
These are workload-based heuristics, not performance guarantees. If speed matters, profile the actual program and access pattern rather than assuming one layout always wins.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesWhat to know about memory layout
Array elements are laid out as structure values, and the implementation accounts for the size of each structure—including any padding—when locating successive elements. A member is accessed according to its position within the structure. Structure size and member offsets can vary with the implementation and declarations, so do not assume a particular size or offset without checking the applicable implementation.
Rank #3
When this pattern is useful
Use an array of structures when your program naturally handles multiple records of one kind, such as points with coordinates, and often reads or updates several fields belonging to each record. If most operations instead traverse one field across many records, consider whether a structure of arrays better matches that access pattern, then measure performance if it is important.
Quick Recap
Best Value
Rank #4
- color: White
- INTRODUCTION TO ALGORITHMS, FOURTH EDITION
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.




