C language: structurally related

xiaoxiao2021-03-06  37

Structure is a more data structure that is re-applied in C language, which can be effective in various data (including various types of data) integrated in a data body, can better implement the structure of the program. , More convenient management data and its operation of data. In the embedded system development, the one hand is due to the serious insufficient system resources, and the other aspect is communicated, interacting, correct and reasonable use of structures, not only can save a valuable resource, but also simplify the design of the program. To make the robustness and maintainability of software design greatly enhanced. The following procedures are debugged on Windows 2000 Visual C 6.0. First examine the size of the structure: struct a {unsigned char code; unsigned int studition;}; if accumulated according to the respective size of each data, the size of the structural A should be: sizeof (char) sizeof (int ) = 5; In fact, the operation results of the above program are: The size of struct a is 8. Why is there such a situation? This is because on the 32-bit operating system, the operating system organization data is a standard in 32-bit (4 bytes), so the size of various variables is generally four times. Moreover, structural data is stored in the order used in the definition, so although the Code variable only occupies one byte, Code Student = 5> 4, so the first 4-bit byte stores Code, the second The 4-digit byte is used to store Student, which actually waste 3 bytes. With the example above, the following examples are not difficult to understand: struct b {unsigned char code; unsigned char result; unsigned int student;}; Structural b SIZE is still 8, Code Result a total of 2 bytes It actually occupies 4 bytes of capacity so that 2 bytes are wasted. The waste of the following structures is more obvious: struct c {unsigned char code; unsigned int student; unsigned char result;

转载请注明原文地址:https://www.9cbs.com/read-62223.html

New Post(0)