Thursday, November 26, 2020

Array of Structures in C

An array of structures in C can be defined as the collection of multiple structures variables where each variable contains information about different entities.

The array of structures in C is used to store information about multiple entities of different data types.

The array of structures is also known as the collection of structures.

In the above given example, a structure of employee is defined which contain three members (id , name, salary).

In the above example emp[2] variable has been declared, which means there is a collection of two employee structures.

Example:

Example of an array of structures that stores information of 5 students and prints it.

#include<stdio.h> 

#include <string.h>   

struct student{   

int rollno;   

char name[10];   

};   

void  main(){   

int i;   

struct student st[5];   

printf("Enter Records of 5 students");   

for(i=0;i<5;i++){   

printf("\nEnter Rollno:");   

scanf("%d",&st[i].rollno);   

printf("\nEnter Name:");   

scanf("%s",&st[i].name);   

}   

printf("\nStudent Information List:");   

for(i=0;i<5;i++){   

printf("\nRollno:%d,
Name:%s",st[i].rollno,st[i].name);   

}       

}    

0 comments:

Post a Comment

Data Structures with C++



NET/SET/CS PG



Operating Systems



Computer Networks



JAVA



Design and Analysis of Algorithms



Programming in C++

Top