
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Explain the array of structures in C language
An array of structure in C programming is a collection of different datatype variables, grouped together under a single name.
General form of structure declaration
The structural declaration is as follows −
struct tagname{ datatype member1; datatype member2; datatype member n; };
Here, struct is the keyword
tagname specifies name of structure
member1, member2 specifies the data items that make up structure.
Example
The following example shows the usage of array of structures in C programming −
struct book{ int pages; char author [30]; float price; };
Array of structures
The most common use of structure in C programming is an array of structures.
To declare an array of structure, first the structure must be defined and then an array variable of that type should be defined.
For Example − struct book b[10]; //10 elements in an array of structures of type ‘book’
Example
The following program shows the usage of 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
", i+1); printf(" Id is: %d
", record[i].id); printf(" Name is: %s
", record[i].name); printf(" Percentage is: %f
",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 Articles
- Explain the concept of union of structures in C language
- Explain structures using typedef keyword in C language
- What is an array of structures in C language?
- Explain array of pointers in C programming language
- Explain the concept of Uninitialized array accessing in C language
- What are nested structures in C language?
- What are pointers to structures in C language?
- Explain pointers and two-dimensional array in C language
- Explain pointers and one-dimensional array in C language
- Explain the history of C language?
- Explain the Format of C language
- Explain the concept of Sorting in C language
- Explain the concept of stack in C language
- Explain the concept of pointers in C language
- Explain the concept of one and two dimensional array processing using C language
