1. The integer types in C language include char, short, int, long, etc. The following are the regulations of C language for the length of each data type:
(a). The lengths of short and long types are different
(b). The int type is usually the same as the physical word length of a specific machine
(c). short is usually 16bits, int is usually 16bits or 32bits. Each compiler can be freely determined based on different hardware, but short and int must be at least 16bits, while long types must be at least 32bits, and short must be more than int and The long type should be short.
2. The sizeof() operator returns the number of bytes contained in a data type (bytes). AnsiC stipulates that sizeof(char) must return 1. When sizeof acts on the array, it returns all members of the array. The number of bytes occupied (note that it is not the number of members in the array). When sizeof() acts on the structure and common body, it returns not only the total number of bytes of the data members, but also the compiler to implement the word Those bytes that the section fills.
In the past, I also vaguely understood these rules by writing programs, but I always thought that the char type must be 8 bits. However, I recently made an embedded DSP project. The compiler manual clearly stated that the char type is 16 bits, but I had no choice but to read it "The C Programming Language "After checking, I found that ANSI C does not make any rigid regulations on the length of the char type. In the past, I didn’t pay much attention to the portability of data types. The previous code used in this project had to recheck the length of the data type.
C++ data type length problem:
1. Bytes and word length
Byte, eight bits are a byte, which is a fixed concept. Word length refers to the length of binary data that a computer can process at one time, and is a non-fixed concept. For example, the word length of an 8-bit computer is 8, that is, one byte, and the word length of a 32-bit computer is 32, that is, 4 bytes. Similarly, the word length of a 64-bit computer is 64, that is, 8 bytes.
2. Data types in C++
1. Character type data char, this type is always a byte length, that is, 8 bits.
2. Plastic surgery int, short plastic surgery and long plastic surgery. Usually int is a word length, short is half a word length, and long is one or two word lengths (one word length in a 32-bit machine).
3. Float, double precision double, and long double precision long double, respectively representing the floating point values of single precision floating point numbers and extended precision. Typically, float is one word, double is two words, and long double is three or four words.
The length of each data type in Java:
Boolean is a trial compilation environment
byte 1 byte
short 2 bytes
char 2 bytes
int 4 bytes
long 8 bytes
float 4 bytes
double 8 bytes