In C, C++, JAVA, int, char, each occupy a few bytes

In C, C++, JAVA, int, char, each occupy a few bytes
int, in C and C++, occupy 2 bytes, in Java, 4 bytes,
char, in C and C+, occupy one byte in
Java, whether it is Both Chinese characters and English letters are expressed in Unicode. A Unicode code is 16 bits, and each byte is 8 bits, so a Unicode code occupies two bytes. However, English letters are special. Are they derived from 8-bit (1 byte) ASCII? So only the lower 8 bits (1 byte) can be used in the Unicode code. It doesn't matter if the upper 8 bits are not used. and so

char c='a';
System.out.println(c.getBytes().lenth()), the result is 1 (byte)

But Chinese characters completely use 16-bit (2 bytes) Unicode, so
char c='中';
System.out.println(c.getBytes().lenth()), the result is 2 (bytes)
Tags: in C, C++, JAVA, int, char, each occupy a few bytes

Guess you like

Origin blog.csdn.net/codemokey/article/details/105810323