Comparison of data type lengths for Java and C + + _java

Source: Internet
Author: User

1. The integer type in the C language has a number of chars, short, int, long, and so on, and the following is the C language's requirement for the length of each data type:
(a). Short and long types are not the same length
(b). 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 determined according to the different freedom of the hardware, but the short and int must be at least 16bits, and the long must be at least 32bits, And the short must be shorter than the int and long types.

2. The sizeof () operator returns the number of bytes (bytes) contained in a data type, Ansic stipulates that sizeof (char) must return 1, and when sizeof acts on an array, it returns the number of bytes in the array (note that it is not the number of members in the array). , when sizeof () acts on the structure and the public body, it returns not only the total number of bytes of data members, but also the bytes that the compiler populates for the byte to implement.

Previously written procedures also vaguely understand these rules, but always thought that the char type must be 8bits, but recently made an embedded DSP project, the compiler manual is clearly written on the char type is 16bits, but turned out "the C programming Language "A check to find out that ANSI C for the length of the char type is not rigidly defined." Previously written programs were less aware of the portability of data types, and the previous code used in this project had to re-examine the length of the data type.

C + + data type length problem:

First, byte and word length
Byte, eight bits is a byte, is a fixed concept. Word length refers to the amount of binary data that a computer can handle at one time, and is an unfixed concept. For example, a 8-bit computer has a word length of 8, that is, a byte, 32-bit computer word length bit 32, that is 4 bytes, similarly, 64-bit computer word length is 64, that is 8 bytes.

Ii. data types in C + +
1, character data char, the type is always one byte long, that is, 8 bits.
2. int, short and long plastic shape. Usually an int is a word length, short is half a word, long is one or 2 words (a word length in a 32-bit machine).

3, floating-point float, double, and long double, which represents the floating-point numbers of single-precision floating-point number double-precision floating-point numbers and extended precision, respectively. Typically, float is a word, a double is two words, and a long double is three or four words.

The length of each data type in Java:

Boolean this test compilation environment is determined by
Byte 1 bytes
Short 2 bytes
Char 2 bytes
int 4 bytes
Long 8 bytes
Float 4 bytes
Double 8 bytes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.