# Array of Structures in C

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.

Let’s take an example:

Here is how we can declare an array of `structure car`. Here `arr_car` is an array of `10` elements where each element is of type `struct car`. We can use `arr_car` to store `10` structure variables of type `struct car`. To access individual elements we will use subscript notation (`[]`) and to access the members of each element we will use dot (`.`) operator as usual.

and so on. Similarly,

Recall that the precedence of `[]` array subscript and dot(`.`) operator is same and they evaluates from left to right. Therefore in the above expression first array subscript(`[]`) is applied followed by dot (`.`) operator. The array subscript (`[]`) and dot(`.`) operator is same and they evaluates from left to right. Therefore in the above expression first `[]` array subscript is applied followed by dot (`.`) operator.

Let’s rewrite the program we used in the last chapter as an introduction to structures.

Expected Output:

How it works:

In lines 5-10, we have declared a structure called the `student`.

In line 14, we have declared an array of structures of type `struct student` whose size is controlled by symbolic constant `MAX`. If you want to increase/decrease the size of the array just change the value of the symbolic constant and our program will adapt to the new size.

In line 17-29, the first for loop is used to enter the details of the student.

In line 36-40, the second for loop prints all the details of the student in tabular form.

## Initializing Array of Structures

We can also initialize the array of structures using the same syntax as that for initializing arrays. Let’s take an example:

### 5 thoughts on “Array of Structures in C”

1. nice

2. how do we return the arr_student[max] back to main() ??

3. Plzzz say to me the array using structure accepts the roll no name & marks optain in 3 subjucts & also find the average of these marks in array

4. QUESTION:
Given the following data that describe an MSU student:
– subject name – semester
– matrix no – address
– CGPA – phone no
– subject taken – parent information
– subject code
Answer the following questions by writing a set of C++ statements:
(a) Declare a structure template for the above data. (10 marks)

(b) Declare an array of type structure declared in (a) with 23 elements. (7 mark)
(c) Declare a variable of type structure declared in question (a). (5 mark)
(d) Prompt a user to enter 12 subject details and store into the array declared in question. (13 marks)
(e) Display the content of the array declared in question (b). (8 marks)
(f) Display the content of the array declared in question (b) only for the subject with 3 credit hour. (7 marks)

Can i get ans for this all questions

5. Great