Use:

#include<stdio.h>

#define n 3

struct body
{
    double p[3]; // Position
    double v[3]; // Velocity
    double a[3]; // Acceleration
    double radius;
    double mass;
};

struct body bodies[n];

int main()
{
    int a, b;
    for(a = 0; a < n; a++)
    {
        for(b = 0; b < 3; b++)
        {
            bodies[a].p[b] = 0;
            bodies[a].v[b] = 0;
            bodies[a].a[b] = 0;
        }
        bodies[a].mass = 0;
        bodies[a].radius = 1.0;
    }

    return 0;
}

This works fine. Your question was not very clear by the way, so match the layout of your source code with the above.

Answer from nims on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ c-array-of-structure
Array of Structures in C - GeeksforGeeks
An array of 2 Person structures is declared, and each element is populated with different peopleโ€™s details. A for loop is used to iterate through the array and print each person's information. Once you have already defined structure, the array of structure can be defined in a similar way as any other variable.
Published ย  October 21, 2025
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_arrays_of_structures.htm
Array of Structures in C
In C programming, the struct keyword is used to define a derived data type. Once defined, you can declare an array of struct variables, just like an array of int, float or char types is declared.
Discussions

Can someone explain how does array of structures work?
You can do it a couple of different ways. You could pre-allocate an array of pointers and allocate each element. Or you can use the handy calloc() function. Or finally you can do as you said just multiply the size of the allocation by the number of elements. You can use the array subscript on the pointer current[i] and the compiler will do the arithmetic for you. calloc() is probably the best since it makes it explicit that you are allocating an array of items, it also will zero the memory for you. More on reddit.com
๐ŸŒ r/C_Programming
21
8
January 15, 2023
How can I create a queue out of structure arrays?
Queue is an abstract data structure; that is to say, only the behavior (FIFO) is specified, and it is not restricted to any particular concrete implementation. Arrays are the best choice to implement small fixed-size queues, but your requirement seems to be that of a linked list based implementation (due to the phrase "queue node" and the member next in TrainDetails structure). Here is a brief outline of the approach (assume that malloc does not fail): Define pointers for the two ends of a queue: TrainDetails *front, *rear; When the first node is added, it will act as both front and rear. Example: (front = rear = malloc(sizeof *rear))->next = NULL; Assign rear->train_id and rear->train_time as per the requirement. Subsequent enqueue operations will change rear to the new node, without changing front. Example: (rear = rear->next = malloc(sizeof *rear))->next = NULL; Conversely, dequeue operations will change front to the next node, without changing rear (except when removing the last node). Example: void *temp = front; front = front->next; free(temp); if (!front) rear = NULL; More on reddit.com
๐ŸŒ r/C_Programming
5
0
August 8, 2022
replicating gnu c's in-struct zero-length arrays
There was a Ziggit discussion on this . More on reddit.com
๐ŸŒ r/Zig
8
15
January 17, 2024
C Question: Having trouble understanding this comment in code - struct of two arrays ensures memory alignment when two separate array declarations doesn't.
Afaik the C standard doesn't guarantee that defining a variable of type msg_data is aligned properly. Same as for a padding that might or might not be present. To guarantee alignment GCC for example has the alignment attribute: https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html More on reddit.com
๐ŸŒ r/embedded
12
6
February 28, 2023
People also ask

Why do we use array of structure in C programming?
It helps store and process a group of similar data records (like multiple students, employees, etc.) in a structured way.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ c-programming โ€บ array-of-structure
Array of Structures in C Programming (With Examples)
How can I initialize an array of structures in C?
You can use a list of values during declaration: struct student s[] = { {"Ram", "10A", 101, {85, 90, 88, 92, 86}}, {"Shyam", "10B", 102, {75, 80, 78, 82, 79}},}; struct student s [ ] = { "Ram" , "10A" , 101 , { 85 , 90 , 88 , 92 , 86 } , { "Shyam" , "10B" , 102 , { 75 , 80 , 78 , 82 , 79 } , } ;
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ array of structure in c
Array of Structure in C Explained with Example
Can structure arrays be global in C?
Yes, you can declare them globally for use across multiple functions.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ c-programming โ€บ array-of-structure
Array of Structures in C Programming (With Examples)
Top answer
1 of 10
149

Use:

#include<stdio.h>

#define n 3

struct body
{
    double p[3]; // Position
    double v[3]; // Velocity
    double a[3]; // Acceleration
    double radius;
    double mass;
};

struct body bodies[n];

int main()
{
    int a, b;
    for(a = 0; a < n; a++)
    {
        for(b = 0; b < 3; b++)
        {
            bodies[a].p[b] = 0;
            bodies[a].v[b] = 0;
            bodies[a].a[b] = 0;
        }
        bodies[a].mass = 0;
        bodies[a].radius = 1.0;
    }

    return 0;
}

This works fine. Your question was not very clear by the way, so match the layout of your source code with the above.

2 of 10
28

Another way of initializing an array of structs is to initialize the array members explicitly. This approach is useful and simple if there aren't too many struct and array members.

Use the typedef specifier to avoid re-using the struct statement everytime you declare a struct variable:

typedef struct
{
    double p[3];//position
    double v[3];//velocity
    double a[3];//acceleration
    double radius;
    double mass;
}Body;

Then declare your array of structs. Initialization of each element goes along with the declaration:

Body bodies[n] = {{{0,0,0}, {0,0,0}, {0,0,0}, 0, 1.0}, 
                  {{0,0,0}, {0,0,0}, {0,0,0}, 0, 1.0}, 
                  {{0,0,0}, {0,0,0}, {0,0,0}, 0, 1.0}};

To repeat, this is a rather simple and straightforward solution if you don't have too many array elements and large struct members and if you, as you stated, are not interested in a more dynamic approach. This approach can also be useful if the struct members are initialized with named enum-variables (and not just numbers like the example above) whereby it gives the code-reader a better overview of the purpose and function of a structure and its members in certain applications.

๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ can someone explain how does array of structures work?
r/C_Programming on Reddit: Can someone explain how does array of structures work?
January 15, 2023 -

Good day,

So I created a structure Position with two int members.

struct Position {
    int x;
    int y;
};

typedef struct Position Position;

int main() {
    Position *current = (Position*)malloc(sizeof(Position));
    ...
}

If I want to create an array of it, should I just multiply it to how many elements I want to use?Does pointer arithmetic will move me to the next element struct every time I add 1 to the pointer?Why when I try to reallocate it by multiplying to higher number, it returns invalid pointer even though I just passed the pointer coming from malloc(). Thanks for answering and have a nice day.

๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ array-of-structure
Array of Structures in C Programming (With Examples)
3 weeks ago - Learn in this tutorial about Array of Structures in C with examples. Understand how to initialize, access, and modify structures to manage data effectively in C.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ array of structure in c
Array of Structure in C - Scaler Topics
April 3, 2024 - It can be coupled with an array to create an array of structures. An array of structures is defined as a collection of structure variables that can, in turn, store various entities.
Find elsewhere
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ array of structure in c
Array of Structure in C Explained with Example
January 4, 2026 - The array s can hold details for three different students. Each element in the array represents one student and holds its own set of member variables. You can also declare structure variables in two ways:
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ array of structures in c language explained with examples
Array Of Structures In C Language Explained With Examples
July 19, 2024 - An array of structures in C is an array (collection of elements) where each element is a structure. It allows us to efficiently store and access complex data.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ array-of-structures-in-c
Array of Structures in C - javatpoint
Array of Structures in C with programming examples for beginners and professionals covering concepts, control statements. Let's see an example of structure with array in C.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ explain-the-array-of-structures-in-c-language
Explain the array of structures in C language
December 6, 2024 - In C programming, the struct keyword is used to define a derived data type. Once defined, you can declare an array of struct variables, just like an array of int, float or char types is declared.
๐ŸŒ
Codesansar
codesansar.com โ€บ c-programming โ€บ array-structure.htm
Array of Structure in C with Examples
An array having structure as its base type is known as an array of structure. To create an array of structure, first structure is declared and then array of structure is declared just like an ordinary array.
๐ŸŒ
Shiksha
shiksha.com โ€บ home โ€บ it & software โ€บ it & software articles โ€บ programming articles โ€บ learn about array of structure in c
Learn About Array of Structure in C - Shiksha Online
July 7, 2023 - Learn about creating, accessing, and manipulating arrays for efficient data management in your C programs. An array of structures in C is a powerful data structure that allows us to represent multiple values with a single variable.
๐ŸŒ
OverIQ
overiq.com โ€บ c-programming-101 โ€บ array-of-structures-in-c
Array of Structures in C - C Programming Tutorial - OverIQ.com
Declaring an array of structure is same as declaring an array of fundamental types. Since an array is a collection of elements of the same type. In an array of structures, each element of an array is of the structure type.
๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ array-of-structures-in-c
Array of Structures in C Programming - DataFlair
March 9, 2024 - Structures help organize related data together. We can create an array of structured data types. An array of structures in C allows for representing multiple instances of a structure as an array.
๐ŸŒ
Study.com
study.com โ€บ computer science courses โ€บ computer science 111: programming in c
Arrays of Structures in C Programming - Lesson | Study.com
December 12, 2018 - To unlock this lesson you must ... of structures in c programming. An array of structures, which are composite data types with collections of variables, works almost the same way as declaring fundamental arrays....
๐ŸŒ
Sdds
intro2c.sdds.ca โ€บ pointers, arrays and structs
Pointers, Arrays and Structs | Introduction to C
The name of an array holds the address of the start of the array; that is, the name of the array is a pointer. Since arrays by definition store element data contiguously in memory, we can access any array element using pointer syntax. This chapter examines this relationship between pointers, arrays and structures in more detail.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ array-of-structures-vs-array-within-a-structure-in-c-and-cpp
Array of Structures vs Array within a Structure in C - GeeksforGeeks
July 15, 2025 - A structure is a data type in C ... elements of different data types - int, char, float, double, etc. It may also contain an array as its member....
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ AoS_and_SoA
AoS and SoA - Wikipedia
November 3, 2025 - Structure of arrays (SoA) is a layout separating elements of a record (or 'struct' in the C programming language) into one parallel array per field.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-define-an-array-of-structures-in-C
How to define an array of structures in C - Quora
Given [code]typedef struct { int length, int width; int height } Rectangle; [/code]The first way is to simply declare an array of that custom type, as follows: [code]Rectangle boxes[5]; [/code]and you have an array of 5 rectangle structures.
๐ŸŒ
Linux Hint
linuxhint.com โ€บ make-array-structs-c
How to Make an Array of Structs in C โ€“ Linux Hint
Above program defines the pointer to object of structure. Malloc function is used to allocate memory for the pointer variable. We initialize the member variables with specific values and print those variables by accessing the members with pointer. a is assigned with 4, b is assigned with โ€˜dโ€™ and c is assigned with float value 5.5. Below is the snapshot of the program and output. ... Now, let us go through the C program for array of structures and array of pointers to structures.