Home Misc What is an unsigned char?

What is an unsigned char?

by nikoo28
0 comment 1 minutes read

Question:

In C, what is an unsigned char used for? How is this different from a regular char?

In C, there are three distinct character types:

  • char
  • signed char
  • unsigned char

If you are using character types for text, use the unqualified char:

  • it is the type of character literals like ‘a’ or ‘0’.
  • it is the type that makes up C strings like “abcde”

It also works out as a number value, but it is unspecified whether that value is treated as signed or unsigned. Beware character comparisons through inequalities – although if you limit yourself to ASCII (0-127) you’re just about safe.

If you are using character types as numbers, use:

  • signed char, which gives you at least the -128 to 127 range.
  • unsigned char, which gives you at least the 0 to 255 range.

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More