Jump to: navigation, search

Description

The char, unsigned char and signed char types are the smallest integer data types in C, taking only one byte of storage by definition. The char type must be large enough to store any member of the basic execution character set.

The number of bits in a char is indicated by the macro CHAR_BIT, defined in limits.h. The minimum, and usual, value of CHAR_BIT is 8, thus giving a range of 0 - 255 for unsigned char, and either -128 or -127 up to 127 for signed char. The actual range on each implementation is indicated by the CHAR_MAX, CHAR_MIN, UCHAR_MAX, SCHAR_MAX and SCHAR_MIN macros, also defined in limits.h.

Unlike the other integer data types, plain 'char' is a separate type from 'signed char'. It is defined by the C implementation to be equivalent in representation and semantics to either 'signed char' or 'unsigned char'. Some C compilers allow the user to choose whether char is signed or unsigned via a command-line switch.

The plain 'char' type is usually used for text handling, as it is the basic element of a C string. The 'unsigned char' type is usually used for manipulating raw binary data in memory, byte by byte.

References

  • ISO C99 Standard, 6.2.5
Personal tools