In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about how to use common body variables in big data. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.
The use of common volume variables
Generally speaking, the common volume variable can not be operated directly as a whole in the program, and all kinds of operations and operations can be completed through the member operation to reference each member variable of the common volume variable.
The general form of a reference common body variable member is:
Share the body variable name. Member name
The member a that accesses the above common body variable U1 is used as follows:
U1.a
If two common body variables use the same common body type definition, they can assign values to each other, for example, the two variables U1 and U2 defined above can assign values to each other.
The common volume variable can also be initialized when it is defined, and its general form is as follows:
Union common type name common volume variable name = {initial value of member 1}
Note: when sharing body variables for initialization, the curly braces to the right of the assignment can only be the initial of the first member.
Value, and curly braces cannot be omitted. For example
Union data
{
Short a
Int b
Double c
}
Union data u = {123}
The running results of the following program are analyzed.
The source code is as follows
1#include
2union data
3 {
4 short n
5 char c [2]
6}
7int main ()
8 {
9 union data d
10 char x
11 d.n=0xFF11
12 printf ("before switching: d.n=%d\ n", d.n)
13 x=d.c [0]
14 d.c [0] = d.c [1]
15 d.c [1] = x
16 printf ("after switching operation: d.n=%d\ n", d.n)
17 return 0
18}
The result of the program running of the complete code:
Run result analysis: the common body type variable d defined in this example has two members, member n is of short type, occupies 2 bytes of memory, and member c is a 2-byte char array, which also occupies 2 bytes. Note that the memory space of members n and c is shared.
Line 11 of the program assigns the member n to the hexadecimal integer 0xFfF11 corresponding to the binary 1111111100010001. The output of line 12 as a decimal signed number is-239.
Lines 13 to 15 of the program swap the two elements of the character array c, where c [0] occupies the same memory space as the first byte of n, and its value binary form is 11111111 occupies the same memory space as the second byte of n. Its value binary form is 00010001. In this way, the exchange of c [0] and c [1] is actually the exchange of the first and second bytes of member n, and the binary form of the value of member n is 0001000111111111.
Therefore, the result of line 16 of the program outputting member n in decimal signed number is 4607.
The above is how to use common body variables in big data. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
File name: checkbox.htmlCheckbox Checkbox < / h4 >
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.