char Character type and byte unit
char Character type and byte unit
char represents characters and defines C's byte: sizeof(char) is 1, but CHAR_BIT need not be 8. The three char types are distinct; char signedness varies.
| Category | Type specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
char c = 'A';
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
letter = A
sizeof(char) = 1
CHAR_BIT = 8
ℹ️ Info The standard guarantees sizeof(char) = 1. CHAR_BIT = 8 reflects the common GCC 10.2 target; other implementations may use a different byte width. This C89 example casts the sizeof result to unsigned long and prints it with %lu.
🏷️ Related type specifiers
📚 Related Tutorials
❓ FAQ
QIs a byte in C always 8 bits?
ANot necessarily. A C byte is an addressable storage unit whose bit count is given by CHAR_BIT in limits.h. Many platforms use 8 bits, but the standard permits other widths.
QIs plain char signed or unsigned by default?
AThat is implementation-defined. Plain char, signed char, and unsigned char are three distinct types. If code depends on sign or numeric range, explicitly choose signed char or unsigned char.
QWhy is sizeof(char) always 1?
Asizeof reports sizes in C-defined bytes, and char occupies exactly one such byte. The value 1 says nothing about 8-bit width or identical physical storage widths across platforms.