Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10-1: Structure.

Similar presentations


Presentation on theme: "Chapter 10-1: Structure."— Presentation transcript:

1 Chapter 10-1: Structure

2 Structure: Definition
Constructed datatype used for packing data of different datatype Structure is a collection of variables of different types under a single name. Convenient tool for handling a group of logically related data item. Helps to organize complex data in a more meaningful way. Various datatype inside structure called member Some other language structure called records and member called fields Structure vs array?

3 Declaring Structure variable
Includes following elements Keyword struct Structure tag name List of variable A terminating semicolon Example

4 Initialization structure
struct book_bank { char title[20]; char authors[15]; int page; float price; } book1 = {“C programming”, “Balagurusami”, 270, 200} book2= {“Muna Madan”, “L.P Devkota”, 100, 19};

5 Example1

6 Declaring after structure is close
Syntax: struct structure_tag_name variable_name; Example2:

7 Accessing structure Member
Syntax StrucutreName.memberVariable;

8 Copying and Comparing structure variable
Can be copies same ways normal variable But for comparing individual members should be compared

9 Array of Structures Can be declared in same way as normal array. Eg 3:

10 Array within structure
Example 4

11 Structure within structure
Example 5

12 Structure and function
Three methods by which values of structure can be transformed Pass each member of structure as a actual argument to function. Not efficient and unmanageable when structure size is large Pass the entire copy of structure. Since function is working on a copy of the structure, any change to structure member are in reflected in original function Use concept of pointer. Pass address

13 Example 6, 7 and 8

14 Union and union vs structure
Left to student


Download ppt "Chapter 10-1: Structure."

Similar presentations


Ads by Google