

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is an array of structures in C language?
The most common use of structure in C programming language is an array of structures.
To declare an array of structures, first the structure must be defined and then, an array variable of that type can be defined.
For example, struct book b[10]; //10 elements in an array of structures of type ‘book’
Example
Given below is the C program for accepting and printing details of 3 students with regards to an array of structures −
#include <stdio.h> #include <string.h> struct student{ int id; char name[30]; float percentage; }; int main(){ int i; struct student record[2]; // 1st student's record record[0].id=1; strcpy(record[0].name, "Bhanu"); record[0].percentage = 86.5; // 2nd student's record record[1].id=2; strcpy(record[1].name, "Priya"); record[1].percentage = 90.5; // 3rd student's record record[2].id=3; strcpy(record[2].name, "Hari"); record[2].percentage = 81.5; for(i=0; i<3; i++){ printf(" Records of STUDENT : %d \n", i+1); printf(" Id is: %d \n", record[i].id); printf(" Name is: %s \n", record[i].name); printf(" Percentage is: %f\n\n",record[i].percentage); } return 0; }
Output
When the above program is executed, it produces the following result −
Records of STUDENT : 1 Id is: 1 Name is: Bhanu Percentage is: 86.500000 Records of STUDENT : 2 Id is: 2 Name is: Priya Percentage is: 90.500000 Records of STUDENT : 3 Id is: 3 Name is: Hari Percentage is: 81.500000
- Related Questions & Answers
- Explain the array of structures in C language
- What are nested structures in C language?
- What is out of bounds index in an array - C language?
- What are pointers to structures in C language?
- What is an identifier in C language?
- What is an anagram in C language?
- Explain the concept of union of structures in C language
- What is a multidimensional array in C language?
- What is an inline function in C language?
- Explain structures using typedef keyword in C language
- What is a two-dimensional array in C language?
- What is a one-dimensional array in C language?
- What is a multi-dimensional array in C language?
- What is an algorithm and flowchart in C language?
- What is an auto storage class in C language?
Advertisements