Why does the Java char primitive take up 2 bytes of memory?

后端 未结 7 736
有刺的猬
有刺的猬 2020-11-30 03:38

Is there any reason why Java char primitive data type is 2 bytes unlike C which is 1 byte?

Thanks

7条回答
  •  眼角桃花
    2020-11-30 04:20

    As we know c suppors ASCII where as java supports Unicode which contains 3 things that is 1-ASCII 2-extended ASCII 3-local language character ASCII is a subset of unicode.ASCII supports only English language where as Unicode supports multinationals language.otherwise java character is encoded within UTF-16 which uses 2 byte.for all of the reason and as the Unicode is the extended version of ASCII ,so it uses 16 bit insted of 8 bit.

提交回复
热议问题