0% found this document useful (0 votes)
4 views

Array Structure

An array of structures allows storing multiple structures of the same type in a single array. The document provides examples of declaring an array of structures and traversing through it to display the data. It includes code snippets for defining a structure and initializing an array of structures with student information.

Uploaded by

Santokh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Array Structure

An array of structures allows storing multiple structures of the same type in a single array. The document provides examples of declaring an array of structures and traversing through it to display the data. It includes code snippets for defining a structure and initializing an array of structures with student information.

Uploaded by

Santokh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ARRAY STRUCTURE

An array of structures is simply an array where each element is a structure.


It allows you to store several structures of the same type in a single array.

 Array of Structure Declaration


the array of structure can be defined in a similar way as any other variable.
struct struct_name arr_name [size];

Example

#include <stdio.h>

struct Student {

int roll;

};

int main() {

struct Student s[2] = { {1}, {2} };

printf("%d\n", s[0].roll);

printf("%d\n", s[1].roll);

return 0;

 Traversal
#include <stdio.h>

#include <string.h>
// Structure definition

struct Student {

char name[50];

int age;

float marks;

};

int main() {

// Declaration and initialization of an array of structures

struct Student students[3] = {

{"Nikhil", 20, 85.5},

{"Shubham", 22, 90.0},

{"Vivek", 25, 78.0}

};

// Traversing through the array of structures and displaying the data

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

printf("Student %d:\n", i+1);

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

printf("Age: %d\n", students[i].age);

printf("Marks: %.2f\n\n", students[i].marks);

}
return 0;

You might also like