tailieunhanh - Lecture Elementary programming with C - Session 11: Advanced data types and sorting

After completing this chapter, students will be able to: Explain structures and their use, define structures, declare structure variables, explain how structure elements are accessed, explain how structures are initialized, explain how assignment statements are used with structures, explain how structures can be passed as arguments to functions, use arrays of structures, explain the initialization of structure arrays. | Advanced Data types and Sorting Session 11 Objectives - 1 Explain structures and their use Define structures Declare structure variables Explain how structure elements are accessed Explain how structures are initialized Explain how assignment statements are used with structures Explain how structures can be passed as arguments to functions Use arrays of structures Explain the initialization of structure arrays Objectives - 2 Explain pointers to structures Explain how structure pointers can be passed as arguments to functions Explain the typedef keyword Explain array sorting with the Selection sort and Bubble sort methods Structures A structure consists of a number of data items, which need not be of the same data type, grouped together The structure could hold as many of these items as desired 1 Variable I L L U S I O N Array I L L U S I O N B A C H 1 } } Name of the book Author Edition Structure Defining a Structure A structure definition forms a template for creating structure variables The variables in the structure are called structure elements or structure members Example: struct cat { char bk_name [25]; char author [20]; int edn; float price; }; Declaring Structure Variables Once the structure has been defined, one or more variables of that type can be declared Example: struct cat books1; The statement sets aside enough memory to hold all items in the structure struct cat { char bk_name[25]; char author[20]; int edn; float price; } books1, books2; Other ways struct cat books1, books2; or struct cat books1; struct cat books2; Accessing Structure Elements Structure elements are referenced through the use of the dot operator (.), also known as the membership operator Syntax: Example: scanf(“%s”, ); Initializing Structures Like variables and arrays, structure variables can be initialized at the point of declaration struct employee { int no; char name [20]; }; Variables emp1 and emp2 of the type employee can be declared . | Advanced Data types and Sorting Session 11 Objectives - 1 Explain structures and their use Define structures Declare structure variables Explain how structure elements are accessed Explain how structures are initialized Explain how assignment statements are used with structures Explain how structures can be passed as arguments to functions Use arrays of structures Explain the initialization of structure arrays Objectives - 2 Explain pointers to structures Explain how structure pointers can be passed as arguments to functions Explain the typedef keyword Explain array sorting with the Selection sort and Bubble sort methods Structures A structure consists of a number of data items, which need not be of the same data type, grouped together The structure could hold as many of these items as desired 1 Variable I L L U S I O N Array I L L U S I O N B A C H 1 } } Name of the book Author Edition Structure Defining a Structure A structure definition forms a template for creating structure .

TỪ KHÓA LIÊN QUAN