In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what the median paragraph and enumeration in the C language mean. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. What is a bit?
The declaration and structure of the bit segment are similar, with two differences:
Members of the ① segment must be int, unsigned int, or signed int
The member name of the ② field is followed by a colon and a number
For example:
Struct A {/ / 4byte=32bit int 4 bytes / / open 4 bytes int _ a: 2; / / 30 (2 bytes allocated, 30 bytes left) int _ b: 5; / / 25 int _ c: 10; / 15 / / opening 4 bytes int _ d: 30 / / exceeds the remaining open memory size. According to the C standard, the previous 15 bytes may be used to open up 15 bytes / / or there may be no need to re-open 30 bytes}
In short: the bit segment is the bit occupied by the specified variable!
two。 Memory allocation, cross-platform and usage of bit segments
Special reminder:
1. The member of the bit segment can be int unsigned int signed int or char (belonging to plastic surgery family) type
two。 The space of the bit segment is opened up according to the need to use 4 bytes (int) or 1 byte (char) (char is exactly int type, disassembly internal processing is int).
3. Bit segments involve many uncertainties. Bit segments are not cross-platform. Portable programs should avoid using bit segments (the problem lies in the use and development of excess memory). For example:
Struct S {char alux 3 position char brang4; struct S s = {0}; s. A = 10; s. B = 12; s. C = 3 x. D = 4
Cross-platform problem of bit segment:
1. It is uncertain whether the int bit segment is treated as a signed or unsigned number.
two。 The number of the largest bits in the segment cannot be determined. (16-bit machine maximum 16-bit machine maximum 16-bit machine maximum 32-bit machine maximum 32, written as 27, there will be problems with 16-bit machines.
3. Whether the members of the bit segment are allocated in memory from left to right or from right to left has not been defined.
4. When a structure contains two segments and the second segment is too large to accommodate the remaining bits of the first segment, it is uncertain whether to discard the remaining bits or to use them.
Conclusion: compared with the structure, the bit segment can achieve the same effect, but it can save space very well, but there are cross-platform problems.
Application of bit segment:
3. What is enumeration?
Enumerations are enumerations one by one, as the name implies.
List the possible values one by one.
For example:
/ / (all values may have a value, starting from 0 by default and increasing by 1 at a time. Of course, you can also assign an initial value when defining) enum Day// week {Mon,Tues,Wed,Thur,Fri,Sat,Sun}; enum Sex// gender {MALE,FEMALE,SECRET} Enum Color// color {RED,GREEN,BLUE}; / / the enum Day, enum Sex, and enum Color defined above are all enumerated types / / {}. The content in the enumerated type is the possible value of the enumerated type, also known as the initialization enum Color// color {RED=1,GREEN=2,BLUE=4} of the enumeration constant / / enumeration. The advantages and use of enumerations
We can use # define to define constants. Why do we have to use enumerations?
Advantages of enumerations:
1. Increase the readability and maintainability of the code
two。 Enumerations are more rigorous with type checking than the identifiers defined by # define.
3. Prevent naming contamination (encapsulation)
4. Easy to debug
5. Easy to use and can define multiple constants at a time
Use of enumerations:
Enum Color / / Color {RED = 1, GREEN = 2, BLUE = 4}; enum Color clr = GREEN; / / you can only assign values to enumerated variables with enumeration constants, so that there is no type difference. Clr = 5; / / this is wrong! This is the end of the article on "what is the meaning of median paragraph and enumeration in C language". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.