Unit VStructures
Unit VStructures
STRUCTURES
Contents
Structures:
• Introduction
• Structures Vs Arrays
• Structure declaration
• Initialization of Structures
• Accessing the members of a Structure
Derived Data Types
s2.average=5.6;
s2.grade = 'B';
//Initialization of structures
struct book b1={"Basic Electronics", 450.00,560};
struct book b2={"Physics", 350.00, 300};
struct book b3={0};
// Accessing structure members
printf("\n%s\t %5.2f\t \t%d\n ",b1.name,b1.price,b1.pages);
printf("\n%s\t %5.2f\t \t%d\n ",b2.name,b2.price,b2.pages);
printf("\n%s\t %5.2f\t \t%d\n ",b3.name,b3.price,b3.pages);
return 0;}
Output:
Basic Electronics 450.00 560
0.00 0
//print the details of 3 books using structures
# include<stdio.h>
int main()
{ struct book { char name;
float price;
int pages; };
struct book b1,b2,b3;
A 67.50 89
B 56.30 70
C 78.00 80