TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
char data type in C is an integral type representing the smallest addressable unit of memory, guaranteed by the C Standard to be exactly one byte (sizeof(char) == 1). While semantically intended for character representation via encodings like ASCII, it is fundamentally an integer type that stores numeric values.
Memory Representation
The exact number of bits in achar is defined by the CHAR_BIT macro in <limits.h>. On virtually all modern architectures, CHAR_BIT is 8, meaning a char occupies 8 bits.
Signedness and Variants
C defines three distinct character types. Unlikeint, where int and signed int are strictly identical, plain char is treated as a unique type by the compiler, though it will share the representation and range of either its signed or unsigned counterpart based on the compiler implementation and target architecture.
char: The default character type. Its signedness is implementation-defined.signed char: Guaranteed to be able to hold negative values. Assuming an 8-bit byte using two’s complement, its range is-128to127(SCHAR_MINtoSCHAR_MAX).unsigned char: Guaranteed to hold only non-negative values. Assuming an 8-bit byte, its range is0to255(0toUCHAR_MAX).
Literals and Initialization
Character literals are enclosed in single quotes. When the compiler encounters a character literal, it translates it to its corresponding integer value based on the execution character set.'A' actually has the type int, not char. When assigned to a char variable, the int value is implicitly converted to char.
Integer Promotion
Becausechar is an integral type with a lower conversion rank than int, it is subject to integer promotion. When a char is used in an arithmetic expression, it is automatically promoted to an int (or unsigned int if int cannot represent all values of the original type) before the operation is performed.
Out-of-Range Conversion Behavior
Because arithmetic operations onchar variables are performed in the int domain due to integer promotion, arithmetic overflow rarely occurs during the operation itself. Instead, boundary behaviors manifest during the integer conversion when the int result is assigned back to the narrower char type.
unsigned char: Converting an out-of-range integer to an unsigned type follows modulo arithmetic. The value is reduced moduloUCHAR_MAX + 1.signed char: Converting an out-of-range integer to a signed type cannot be represented by the target type. According to the C standard (pre-C23), this results in Implementation-Defined Behavior (or raises an implementation-defined signal). As of C23, this conversion is well-defined to wrap around using two’s complement.
Master C with Deep Grasping Methodology!Learn More





