Right arrow

Array of Structures in C: Syntax, Examples, Programs & Interview Questions

author image

Bosscoder Academy

Date: 2nd August, 2026

feature image

While preparing C programming for placements, university tests, or software engineering interview, you will be at some point of time required to store multiple entries of similar kind. This is where the concept of Array of Structures in C comes into play.

Rather than defining variables for each student, employee, or item, you can utilize the concept of structure along with that of array to store large number of data entries.

In this tutorial, you will get to know about what an array of structure is, syntax of array of structure, examples and interview questions.

Quick Hint: Consider structure as the blueprint of one entry and array of structure as the storage of many such entries.

What is Array of Structures in C Programming Language?

Array of structures is a collection of structure variables that have the same data type.

With the help of this concept, you will be able to save several records of the same structure type in a single array.

For example, suppose you want to save details of 100 students. In such a case, you won't need 100 different structure variables. All you have to do is define one array of structures.

What is an Array of Structures in C?

An array of structures in C language is an array where each array element is a structure.

This type of array is employed in situations where there is a need to store several records of the same fields.

Instead of declaring different variables for each student:

struct Student s1;
struct Student s2;
struct Student s3;

You can simply write:

struct Student students[3];

Now each element in the array is a student record.

Syntax of an Array of Structures

struct Student {
    int rollNo;
    char name[45];
    float marks;
};

struct Student students[5];

Here:

  • Student is the structure type.
  • students is an array containing 5 student records.

Each record has roll number, name, and marks.

How to Access an Array of Structures

Access using index number followed by the dot (.) operator.

students[0].rollNo = 123;
students[0].marks = 89.5;

Also,

students[1].name
students[2].marks
students[4].rollNo

Where each index stands for a separate structure object.

Note: Arrays make use of square bracket [], whereas structure elements use dot (.) operator.

Program to Input and Display Student Details

#include <stdio.h>

struct Student {
    int rollNo;
    char name[30];
    float marks;
};

int main() {

    struct Student students[3];

    for(int i = 0; i < 3; i++) {

        printf("Enter Roll Number: ");
        scanf("%d", &students[i].rollNo);

        printf("Enter Name: ");
        scanf("%s", students[i].name);

        printf("Enter Marks: ");
        scanf("%f", &students[i].marks);
    }

    printf("\nStudent Details\n");

    for(int i = 0; i < 3; i++) {

        printf("\nRoll No: %d", students[i].rollNo);
        printf("\nName: %s", students[i].name);
        printf("\nMarks: %.2f\n", students[i].marks);
    }

    return 0;
}

Output:

Enter Roll Number: 101
Enter Name: Rahul
Enter Marks: 92

Enter Roll Number: 102
Enter Name: Aman
Enter Marks: 88

Student Details

Roll No: 101
Name: Rahul
Marks: 92.00

Roll No: 102
Name: Aman
Marks: 88.00
Interview Tip: The above sample uses arrays, structures, loops, and user input, which are common coding interview topics.

Why Should You Use an Array of Structures?

Here are some reasons why you should use an array of structures:

  • Can store many entries.
  • Reduces repetitive code.
  • Code becomes more maintainable.
  • Easy to find, update, and display records.
  • Increases code readability.

Common examples of using an array of structures include:

  • School management system
  • Employees database
  • Library management system
  • Inventory management system
  • Banking system
Bosscoder Academy Program

Structure vs Array of Structures

Structure Array of Structures
Stores a single record. Stores multiple records.
Represents a single object. Represents a collection of similar objects.
Does not require any indexing. Records can be accessed by array index values.
Suitable for a single entity. Suitable for multiple entities.

Example

struct Student student;

holds one student.

struct Student students[100];

Passing an Array of Structures to a Function

Arrays of structures can be passed to functions as well.

#include <stdio.h>

struct Student {
    int rollNo;
    float marks;
};

void display(struct Student s[], int size) {
    for(int i = 0; i < size; i++) {
        printf("%d %.2f\n", s[i].rollNo, s[i].marks);
    }
}

The above strategy is very common in C programming languages.

Memory Representation

All structures have a definite memory size.

When you declare an array of structures, the memory space is allotted continuously to all the records.

For instance:

students[0]
students[1]
students[2]
students[3]

All these structures get laid out contiguously in memory and this makes it easy to traverse them through loops.

Fun Fact: Array elements get laid out contiguously in memory and that is why accessing any record using its index is done in constant time.

Time Complexity of Array Operations in C

Operation Time Complexity
Access by Index O(1)
Traversal O(n)
Linear Search O(n)
Update Record O(1)

Knowing this time complexity is very useful for technical interviews.

Real World Application

Suppose you want to make an employee management application.

Rather than using this:

struct Employee emp1;
struct Employee emp2;
struct Employee emp3;C

All you need to write is this:

struct Employee employees[100];

And now you can use loops to do the following:

  • Add an employee
  • Update record
  • Display all records
  • Search employees

This makes the program much cleaner and scalable.

Want to practice another important C programming concept? Read our blog on How to Write a Fibonacci Series in C and learn the logic, syntax, recursion, and complete C programs.

Common Mistakes to Avoid

Beginners make these errors while working with arrays of structures:

  • Ignoring to use the array index.
  • Using . instead of -> with structure pointers.
  • Accessing index value that does not exist in the array.
  • Creating an array that is too small for your needs.
  • Not initializing the members of structure before using them.
Tip: When you have multiple records stored, use combination of loops and arrays of structures.

Interview Questions on Arrays of Structures in C

Some common interview questions on arrays of structures in C are as follows:

  1. What do you mean by arrays of structures in C?
  2. Why we use arrays of structures in C?
  3. How do we access the members of arrays of structures?
  4. What is the difference between structure and arrays of structures?
  5. Can we pass an array of structures to a function?
  6. How do we allocate memory for arrays of structures?
  7. What is the time complexity of access operation in array of structures?

Practice these questions to get ready for your technical interviews in product based companies.

Improve Your Programming Skills

Learning about array of structures is vital to write an efficient program using C. But technical interview questions from product-based companies are not only limited to C programming but involve concepts such as problem solving, data structures, algorithms, and systems.

If you are working professional looking forward to upgrade your skills or change your job profile, Bosscoder Academy has learning paths, mentoring, mock interviews, and practice that will assist you in developing coding basics and preparing for software engineering interviews.

Key Takeaways

  • Array of structures holds several records of the same structure type.
  • It combines both properties of arrays and structures.
  • Records can be accessed using the index number of the array along with the dot operator.
  • It is helpful in managing large amounts of related data.
  • Array of structures is used widely in software and coding interviews.

Conclusion

The concept of array of structures in C is quite simple but very useful in efficiently managing several records. Through the combination of arrays and structures, you can write efficient programs in C.

Knowing how to work with arrays of structures will be very helpful whether you are preparing for placements, technical interviews, or writing C programs/projects.

Frequently Asked Questions (FAQs)

Q1. What is an array of structures in C?

An array of structures is an array where each element is a structure, allowing you to store multiple records of the same type.

Q2. Why do we use an array of structures?

It will help us to handle various records efficiently without having repetitive codes and improving readability.

Q3. Is it possible to pass an array of structures to a function?

Yes. Like other arrays, array of structures can be used to pass values in a function.

Q4. Where are arrays of structures used?

Arrays of structures are used in student management system, employee database system, inventory management, bank system, and library management system.