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.