0

I was just reviewing data types on codecademy and saw the description about char data type. It says:

Characters typically require 1 byte of memory space and range from -128 to 127.

What is "range from -128 to 127"? For more clarification here's a screenshot:

]

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • That's the range of values that a signed `char` can hold... – Cody Gray - on strike Oct 23 '21 at 04:24
  • Characters are represented within a program by their numerical values (e.g. `a` is 97 if using ASCII) and so `char` is really an integer type. However that claim is not universally true; on many platforms `char` is unsigned and ranges from 0 to 255. More exotic ranges are also possible. – Nate Eldredge Oct 23 '21 at 04:24

2 Answers2

0

A signed 8-bit integer can represent the numbers from -128 to 127. The ASCII encoding associates those numbers with characters.

Brady Dean
  • 3,378
  • 5
  • 24
  • 50
-1

That means that type char can store a value from -128 to 127. And the system will change that number into a character using ACSII. If you assign it to a value bigger than 127 or lower than -128, it will result in an overflow. which result to undefined behavior.

  • 2
    Note that overflow of a signed integer type is *undefined behavior*, which means that you cannot demonstrate it with a code snippet. – Cody Gray - on strike Oct 23 '21 at 04:26
  • The system's display will treat `char` values as characters according to the character encoding that the system uses. That is often ASCII (almost always, these days), but there are other character encodings. – Pete Becker Oct 23 '21 at 13:31