# Session 11

## | 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 .

TÀI LIỆU LIÊN QUAN
32    34    1
7    26    0
55    27    2
23    75    0
23    35    0
7    21    0
9    116    28
33    15    0
29    37    0
8    39    0
TÀI LIỆU XEM NHIỀU
13    16459    557
3    10302    81
25    10167    2148
37    9576    2521
20    9439    954
14    8656    1843
8    7823    1651
23    7047    261
2    6880    133
17    6627    174
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
77    6    2    19-06-2021
147    9    1    19-06-2021
19    5    1    19-06-2021
6    8    1    19-06-2021
3    4    1    19-06-2021
136    3    1    19-06-2021
147    2    1    19-06-2021
4    16    1    19-06-2021
232    6    1    19-06-2021
17    8    1    19-06-2021
98    7    1    19-06-2021
142    14    2    19-06-2021
8    6    1    19-06-2021
115    1    1    19-06-2021
2    6    1    19-06-2021
10    4    1    19-06-2021
27    6    1    19-06-2021
131    16    2    19-06-2021
79    7    1    19-06-2021
2    4    1    19-06-2021
TÀI LIỆU HOT
3    10302    81
13    16459    557
3    817    70
580    2779    274
584    1392    57
62    2927    1
171    2602    475
2    1142    57
51    1394    75
53    1916    81