Can the char type be categorized as an integer?

前端 未结 8 2613
盖世英雄少女心
盖世英雄少女心 2020-12-01 22:32

Just now I read \"char is the only unsigned integral primitive type in Java.\" Does this mean the char is one of the integral types in Java?

Same as in C, recently I

8条回答
  •  长情又很酷
    2020-12-01 23:23

    According to the Java Primitive Data Types tutorial:

    char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

    So yes, it is a 16-bit unsigned integer. Whether you use the type to represent a number or a character is up to you...


    Also keep in mind that while the char type is guaranteed to be 16 bits in Java, the only restriction C imposes is that the type must be at least 8 bits. According to the C spec reference from this answer:

    maximum number of bits for smallest object that is not a bit-field (byte)

    CHAR_BIT 8

    So a char in C does not necessarily represent the same range of integer values as a char in Java.

提交回复
热议问题