Difference between Array of Structures and Array within Structures

Below is the tabular difference between the Array within a Structure and Array of Structures:

Parameter  

Array within a Structure

Array of Structures

Basic idea A structure contains an array as its member variable. An array in which each element is of type structure.
Syntax struct class { int ar[10]; } a1, a2, a3; struct class { int a, b, c; } students[10];
Access Can be accessed using the dot operator just as we access other elements of the structure. Can be accessed by indexing just as we access an array.
Access elements syntax structure.array[index] array[index].member
Memory Structure Array within the structure will be stored in sequential memory and structure padding is not dependent on the size of the array. There will be some empty space between structure elements due to structure padding.


Array of Structures vs Array within a Structure in C

Both Array of Structures and Array within a Structure in C programming is a combination of arrays and structures but both are used to serve different purposes.

Similar Reads

Array within a Structure

A structure is a data type in C that allows a group of related variables to be treated as a single unit instead of separate entities. A structure may contain elements of different data types – int, char, float, double, etc. It may also contain an array as its member. Such an array is called an array within a structure. An array within a structure is a member of the structure and can be accessed just as we access other elements of the structure....

Array of Structures

...

Difference between Array of Structures and Array within Structures

An array is a collection of data items of the same type. Each element of the array can be int, char, float, double, or even a structure. We have seen that a structure allows elements of different data types to be grouped together under a single name. This structure can then be thought of as a new data type in itself. So, an array can comprise elements of this new data type. An array of structures finds its applications in grouping the records together and provides for fast access....