Search Your Topic

config
Wednesday, 21 June 2017 03:11

Array of Structures in C

Written by
Rate this item
(0 votes)

There can be array of structures in C programming to store many information of different data types. The array of structures is also known as collection of structures.

Let's see an example of structure with array that stores information of 5 students and prints it.

 
  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. #include<string.h>  
  4. struct student{  
  5. int rollno;  
  6. char name[10];  
  7. };  
  8. void main(){  
  9. int i;  
  10. struct student st[5];  
  11. clrscr();  
  12. printf("Enter Records of 5 students");  
  13.   
  14. for(i=0;i<5;i++){  
  15. printf("\nEnter Rollno:");  
  16. scanf("%d",&st[i].rollno);  
  17. printf("\nEnter Name:");  
  18. scanf("%s",&st[i].name);  
  19. }  
  20.   
  21. printf("\nStudent Information List:");  
  22. for(i=0;i<5;i++){  
  23. printf("\nRollno:%d, Name:%s",st[i].rollno,st[i].name);  
  24. }  
  25.   
  26. getch();  
  27. }  

Output:

Enter Records of 5 students
Enter Rollno:1
Enter Name:Sonoo
Enter Rollno:2
Enter Name:Ratan
Enter Rollno:3
Enter Name:Vimal
Enter Rollno:4
Enter Name:James
Enter Rollno:5
Enter Name:Sarfraz

Student Information List:
Rollno:1, Name:Sonoo
Rollno:2, Name:Ratan
Rollno:3, Name:Vimal
Rollno:4, Name:James
Rollno:5, Name:Sarfraz


Read 222 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.