TAILIEUCHUNG - A Complete Guide to Programming in C++ part 29

A Complete Guide to Programming in C++ part 29. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | unions 259 Memory Usage In normal classes each data member belonging to an object has its own separate memory space. However a union is a class whose members are stored in the same memory space. Each data member has the same starting address in memory. Of course a union cannot store various data members at the same address simultaneously. However a union does provide for more versatile usage of memory space. Definition Syntactically speaking a union is distinguished from a class defined as a class or struct only by the keyword union. Example union Number long n double x Number numberl number2 This example defines the union Number and two objects of the same type. The union Number can be used to store either integral or floating-point numbers. Unless a private label is used all union members are assumed to be public. This is similar to the default setting for structures. This allows direct access to the members n and x in the union Number. Example 12345 Storing an integer 3 and multiply by 3. Floating point number The programmer must ensure that the current content of the union is interpreted correctly. This is normally achieved using an additional type field that identifies the current content. The size of a union type object is derived from the longest data member as all data members begin at the same memory address. If we look at our example the union Number this size is defined by the double member which defaults to 8 sizeof double byte. The example opposite defines the union WordByte that allows you to read or write to a 16-bit memory space byte for byte or as a unit. 260 CHAPTER I 3 DEFINING CLASSES EXERCISE Struct tm in header file ctime struct tm int tm_sec int tm_min 0 - 59 60 0 - 59 int tm_ _hour 0 - 23 int tm_ _mday Day of month 1 - 31 int tm_ mon Month 0 - 11 January 0 int tm_ _year Years since 1900 Year - 1900 int tm_ _wday Weekday 0 - 6 Sunday 0 int tm_ _yday Day of year 0 - 365 int tm_ _isdst Flag for summer-time .

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.