What is array ? 
An array is a collection of variables of the same data type that 
are referenced by a common name . 
Eg: 
int arr[3]; 
0 (2bytes) 1(2bytes) 2(2bytes) 
arr[0] arr[1] arr[2]
What is structure ? 
A structure is a grouping of several variables of different 
data types. Struct keyword is used. 
Eg: 
struct book 
{ int page; (2bytes) (15bytes) (4bytes) 
char author[15]; page author price 
float price; 
};
What is Arrays of structures ? 
Since an array can contain similar elements , the 
combination having structures within array is an 
array of structures .
Arrays of structures 
Eg: 
struct fraction 
{ 
int numerator; // 2 bytes 
int denominator; //2 bytes 
}; 
Struct fraction f1[4]; // this is an array of structure
Memory allocation of arrays of structures 
Total size of f1 = 4*2*2=16 bytes 
0 (4) 1 (4) 2 (4) 3(4) 
N D N D N D N D 
f1[0] f1[1] f1[2] f1[3]
Accessing the elements of array of structure 
Struct fraction f1[4]; 
For(i=0;i<4;i++) 
{ 
Printf(“%d”,f1[i].numerator); 
Printf(“%d”,f1[i].denominator); 
}
Thank you 
Any queries ? 
prepared by : 
Arushi

arrays of structures

  • 2.
    What is array? An array is a collection of variables of the same data type that are referenced by a common name . Eg: int arr[3]; 0 (2bytes) 1(2bytes) 2(2bytes) arr[0] arr[1] arr[2]
  • 3.
    What is structure? A structure is a grouping of several variables of different data types. Struct keyword is used. Eg: struct book { int page; (2bytes) (15bytes) (4bytes) char author[15]; page author price float price; };
  • 4.
    What is Arraysof structures ? Since an array can contain similar elements , the combination having structures within array is an array of structures .
  • 5.
    Arrays of structures Eg: struct fraction { int numerator; // 2 bytes int denominator; //2 bytes }; Struct fraction f1[4]; // this is an array of structure
  • 6.
    Memory allocation ofarrays of structures Total size of f1 = 4*2*2=16 bytes 0 (4) 1 (4) 2 (4) 3(4) N D N D N D N D f1[0] f1[1] f1[2] f1[3]
  • 7.
    Accessing the elementsof array of structure Struct fraction f1[4]; For(i=0;i<4;i++) { Printf(“%d”,f1[i].numerator); Printf(“%d”,f1[i].denominator); }
  • 8.
    Thank you Anyqueries ? prepared by : Arushi