Negative ASCII value

前端 未结 6 1390
太阳男子
太阳男子 2020-12-09 19:33

What\'s the point of negative ASCII values?

int a = \'«\'; //a = -85 but as in ASCII table \'<<\' should be 174
6条回答
  •  一生所求
    2020-12-09 19:57

    There is no such thing. ASCII is a table of characters, each character has an index, or a position, in the table. There are no "negative" indices.

    Some compilers, though, consider char to be a signed integral data type, which is probably the reason for the confusion here.

    If you print it as unsigned int, you will get the same bits interpreted as a unsigned (positive) value.

提交回复
热议问题