arrays of structures

arushibhatnagar 2,839 views 8 slides Aug 25, 2014
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

this presentation includes the whole concept of arrays of structure. it is sufficient


Slide Content

Arrays of Structures

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]; (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
Tags