Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

C Array of Structures


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. for(i=0;i<5;i++){
  14. printf(“\nEnter Rollno:”);
  15. scanf(“%d”,&st[i].rollno);
  16. printf(“\nEnter Name:”);
  17. scanf(“%s”,&st[i].name);
  18. }
  19. printf(“\nStudent Information List:”);
  20. for(i=0;i<5;i++){
  21. printf(“\nRollno:%d, Name:%s”,st[i].rollno,st[i].name);
  22. }
  23. getch();
  24. }

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

Comments

comments