Getting Started With C

Definition

Arrays within structures in C allow you to define a structure that contains an array as one of its members. This enables you to organize and store related data in a more structured and logical manner.

Syntax:

struct structure_name {
          data_type member1;
          data_type member2;
          // ...
          data_type array_member[N];  // Array as a member
          // ...
      };
      
  • Examples :

    Program.c


  • The program defines a structure Student with members name, age, and marks (an array of floats).
                It initializes a structure variable student1 with sample data.
                It prints the student's name, age, and marks using the structure variable.
                

    Output:

          Student Name: John Doe
        Age: 20
        Marks: 85.50 90.00 78.50 92.00 88.50 
        
        
        

    Resources :

    Test Your Knowledge
    Choose The

    With supporting text below as a natural lead-in to additional content.

    Q1. What is the primary advantage of using arrays within structures in C?

    Q2. If you want to access the employees array of the second company in the corporations array, what is the correct syntax?