C
|
32-bit machine |
64-bit Machine |
| Char |
1 |
1 |
Int
|
4 |
4 |
Long
|
4 |
8 |
| Float |
4 |
4 |
| Double |
8 |
8 |
| char * |
8 |
8 |
Second, C + +
1. 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 process at a time and is a non-fixed concept. For example,8the word length of the bit computer is8, that is, a single byte, +bit computer's word length bit +, i.e.4bytes, in the same vein, -the word length of the bit computer is -, i.e.8bytes.
2.char type is always a byte long, i.e. 8 bit.
3.int , Short int and the Long int
usuallyintfor a word length, Shorthalf a word length,Longfor one or2Word length(in the +bit machine for a word length).
4. floating-point float double , and long double precision long double
in typical cases, float as a word, Double is two words, long Double is three or four characters.
Java
1.in theC + +in whichCharis the underlying data type,8bit,1a byte. byteis not an underlying data type, typicallytypedef unsigned char byte;In this way, that is to say,byteis actuallyunsigned chartype, it is also8bit,1a byte. The difference is thatCharthe range that can be represented is-128-127, whilebytethe range that can be represented is0-255.
2. in Java
in Java , bothchar and byte are the underlying data types, where byte is the same as the char type in C + + . 8 -bit,1 -byte,-128-127. However, thechar type is 2 bytes,' \u0000 '-' \uffff '.
why The Java char is 2 bytes?
3. because Java is internally Unicode , java is actually supporting Chinese variable names, such as string world = " my World "; Such statements can be passed.
4. Supplement:
C + + , the number of bits and bytes of some data is related to the machine operating system, hardware, and so on.
in Java , the operating system, hardware-independent, because Java is running on the virtual machine, so the data size is fixed.
Java in the Long is fixed 8 bytes, - bit; int is a 4 bytes, + bit
Length of various data types in C, C + +, and Java