In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what are the data types in C language". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "what are the data types in C language".
The storage of data should first talk about the type of data, which determines the perspective of memory space.
The data types of C language are divided into built-in type and external type.
1. Built-in type (1) integer array
Char (character type), short (short integer), int (integer), long (long integer) (signed or unsigned)
(2) floating point type
Float (single precision floating point), double (double precision floating point)
two。 Custom type
(1) Array type
It is important to note that removing the array name is the type of the array.
For example, int arr [10], excluding the array name arr,int [10] is the array data type.
(2) structure type (struct)
(3) enumerated types (enum)
(4) Association type (union)
3. Pointer type 4. Null type (void)
The form of data storage is based on the original code and anti-code complement of the computer.
Floating-point type: not stored in the form of original countercompensation
Other numbers are divided into signed and unsigned numbers.
Unsigned number: the original countercomplement of unsigned number is consistent, and there is no difference when it is stored.
Sign number: the original and inverse complement of a positive number is the same, but the original and inverse complement of a negative number needs to be transformed by operation (the highest bit of the positive number is 0, the highest bit of the negative number is 1).
Original code: translates a binary into a binary number in the form of a positive or negative number
Reverse code: invert every bit of the original code
Complement: inverse + 1
A binary sequence complement that generally stores numbers when stored.
At the same time, there is a large and small end of data storage.
The memory space has a number, the one with small number is the low address, and the one with large number is the high address.
Large-end storage: the low order of data is stored in the high address of memory.
Small-end storage: the low bit of data is stored in the low address of memory.
The storage mode of each machine is different, and you can use the following simple code to observe which storage mode the computer is.
# includeint main () {int a = 1; char* p = (char*) & a / / the forced conversion of an integer address to a character does not affect the storage of the address, but only affects the read / / pointer to determine the number of bits in the read memory. The character pointer only solves 1 byte when dereferencing. When the integer pointer is dereferenced, an is a positive number. The original countercomplement is the same / / 00000000 00000000 00000000 00000001 if / pointer can only read the first 8 bits of the memory after forced conversion to character type / / if the dereferencing result of the pointer is 1, the data storage result is 00000001 0000000000000000000000001 (* p = = 1) {printf ("small end\ n"). } else {printf ("big end\ n");} return 0;} character type
The corresponding storage range of char/signed char is-128 to 127, and 10000000 is-128.
In order to understand signed and unsigned, the following examples apply
# includeint main () {unsigned int i; for (I = 9; I > = 0) Before the loop starts, it should be noted that I needs to be less than 0 before the loop will stop / / but at this time I is a unsigned type, and there is no way to break the loop because it is stored without a symbol bit. / / the loop is an endless loop {printf ("% d", I);}}
The difference between signed and unsigned lies in whether it can represent positive and negative numbers.
Whether there are symbolic bits when storing data
Storage of signed char and char types can also be illustrated by a diagram.
The middle dividing line is the positive and negative dividing line, and the first place is the symbol bit. A symbol bit of 1 is a negative number, and a symbol bit of 0 is a positive number
To understand the storage scope of char, borrow the following example
# include#includeint main () {char a [1000]; int i; for (I = 0; I < 1000; iTunes +) {a [I] =-1-I;} printf ("% d", strlen (a)); return 0 } / / I is of type int and can grow with the loop, but for an array of a, there is a limited amount of data that can be stored. / / Array an is of character type. The range of character array is-128 to 127, with a total of 255 numbers, so the length of the array is also 255.
Running result: 255
The storage mode of int and other types is similar to that of char, so I won't repeat it here.
An example is used to prove that floating point storage is different from integer storage.
# includeint main () {int n = 9; float* pfloat = (float*) & n; printf (the value of "n is:% d\ n", n); printf (the value of "* pfloat is:% f\ n", * pfloat); / / here the data stored in the shaping is fetched with a single-precision floating-point pointer * pfloat = 9.0 Printf (the value of "n is:% d\ n", n); printf (the value of "* pfloat is:% f\ n", * pfloat); / / here the number originally stored in the integer is changed by the pointer of the single-precision floating-point type and changed to the single-precision floating-point number return 0;}
Output result:
The value of n is: 9
* the value of pfloat is 0.000000
The value of n is 1091567616
* the value of pfloat is 9.000000
Thus it can be seen that the single-precision floating-point pointer can not successfully retrieve the number originally stored in the shaping, and the value of the shaping changed by the single-precision floating-point pointer in the second step cannot be successfully accessed, and the number printed is not 9. Thus it can be seen that there is a big difference between the two storage methods, so we will explain the floating-point storage mode.
Floating point type
Floating-point type does not rely on the original countercomplement of data for storage.
Floating point type has its own special rules.
(e can also be understood as the order corresponding to the highest item)
Prove it with an example
For example, the floating point number 8.5
Convert to binary
1000.1
For this number, the form stored in the graph is
(- 1) ^ 0 * 1.0001 * 2 ^ 3
Storage is
0 00000011 00000000000000000010001
At this point, assuming that the memory we are applying for is a bar, then the data storage for floating-point numbers is shown in the figure.
Single-precision floating-point type corresponds to the figure 1, SME is distributed in different locations, figure 2 shows double-precision floating-point type, double-precision and single-precision floating-point type corresponding to E and M is different.
(1)
That is, the value of E cannot be all 0 or 1, and the stored value of E is different from the real value.
In order to represent a minimal decimal, such as 1 * 10 ^-10, E cannot represent a negative number because E itself does not have a symbolic bit.
Single precision: e = true value + 127
Double precision: e = true value + 1023
After it is added, it is converted to binary storage into E, and this number is subtracted when it is taken out and used.
Special case 1PUR E is all 0
The real value of single precision E at this time is-127, and the floating point number is almost equal to 0, which is an almost non-existent number.
Special case 2PUR E is all 1
The real value of single precision E is 128 at this time, and the floating point number is a positive or negative infinite number.
(2)
For M, since the value of M is between the interval [1pm 2), the value in the integer part must be 1.
Reuse single-precision floating-point storage 8.5
The M of this number is 1.0001
In order for the floating point number to express a larger number, and the number in the single bit in M is fixed at 1, it is then stipulated that the 1 in the bit in M can no longer be stored and can be added when it is accessed.
The above is all the content of the article "what are the data types in C language?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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.
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.