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

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.