Java and c and c++ data type length comparison

  • 2020-04-01 02:52:14
  • OfStack

1. The integer types in c language include char, short, int, long, etc. The following is the length of each data type specified by c language:
(a) short and long have different lengths
(b). Int is usually the same as the physical word length of the specific machine
(c). Short is usually 16bits, int is usually 16bits or 32bits each compiler is free to determine depending on the hardware, but short and int must be at least 16bits, and long must be at least 32bits, and short must be shorter than int and long.

2. The sizeof () operator returns is a type of data contained in the number of bytes (bytes), AnsiC rules sizeof (char) must return 1, when the sizeof ACTS on the array, returns an array of all the members of the number of bytes (note that is not the number of members in the array), when the sizeof () when acting on the structure and the public body, return is not only a data member of the total number of bytes, also includes the compiler in order to achieve the bytes and fill the bytes.

In The past, writing programs also vaguely understand these rules, but always thought that char type must be 8bits, but recently did an embedded DSP project, compiler manual clearly wrote that char type is 16bits, but turned out "The C Programming Language" to find that ANSI C for The length of char type is not rigid. The previous code used in this project had to be rechecked for the length of the data type.

C++ data type length problem:

Bytes and word length
A byte, eight bits is a byte, is a fixed concept. Word length is the length of binary data that a computer can process at a time. For example, an 8-bit computer has a word length of 8, or one byte, and a 32-bit computer has a word length of 32, or four bytes. Similarly, a 64-bit computer has a word length of 64, or eight bytes.

Data types in C++
1, character data char, this type is always one byte long, that is, 8 bits.
2. Int, short and long. Int is usually one word long, short is half a word long, and long is one or two word long (in 32-bit machines, one word long).

Float, double precision double, and long double precision long double, respectively, represent single precision floating point double precision floating point number and extended precision floating point value. Typically, float is one word, double is two words, and a long double is three or four words.

Length of each data type in Java:

Boolean this is a trial compilation environment
Byte  1 byte
Short 2 bytes
Char  2 bytes
Int    4 bytes
Long  8 bytes
Float is 4 bytes
Double 8 bytes


Related articles: