October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Array of Structures: How Records, Indexes, and Fields Fit Together

An array of structures stores multiple records of one structure type. Learn how indexing and member access work in C, plus how AoS differs from SoA.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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. Define the structure type, as struct point is defined above.
  2. Declare an array with that type and a size, such as struct point points[3];.
  3. Optionally initialize its elements with aggregate initializers, such as {{2, 3}, {4, 5}, {6, 7}}.
  4. 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
Sale
Data Structures and Algorithms in Python
  • Used Book in Good Condition
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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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

SaleBestseller No. 1
SaleBestseller No. 2
Data Structures and Algorithms in Python
Data Structures and Algorithms in Python
Used Book in Good Condition
$125.13
SaleBestseller No. 4
Introduction to Algorithms, fourth edition
Introduction to Algorithms, fourth edition
color: White; INTRODUCTION TO ALGORITHMS, FOURTH EDITION
$99.47
SaleBestseller No. 5
Rank #4
Sale
Introduction to Algorithms, fourth edition
  • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.