Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The char type in C++ is a fundamental integral data type designed to represent a single character. It is guaranteed by the C++ Standard to be exactly one byte in size (sizeof(char) == 1), making it the smallest addressable unit of memory in the language. Under the hood, a char stores an integer value that corresponds to a specific character in the execution character set (typically ASCII). Because it is an integral type, it supports standard arithmetic and bitwise operations.
// Character literal initialization (enclosed in single quotes)
char letter = 'A'; 

// Integer initialization (ASCII value of 'A')
char ascii_letter = 65; 

// Arithmetic operation on a char
char next_letter = letter + 1; // Results in 'B' (66)

Signedness and Distinct Types

Unlike int, where int and signed int are identical, the C++ standard defines three distinct character types. The signedness of a plain char is implementation-defined; the compiler dictates whether it behaves as signed or unsigned based on the target architecture and compiler flags.
  • char: The default type used for character literals. Range depends on the compiler’s default signedness.
  • signed char: Explicitly signed. Guaranteed range of at least -127 to 127 (typically -128 to 127 on modern two’s complement systems).
  • unsigned char: Explicitly unsigned. Guaranteed range of 0 to 255.
char default_char = 200;          // Value interpretation depends on compiler signedness
signed char negative_char = -50;  // Explicitly signed, valid range
unsigned char raw_byte = 255;     // Explicitly unsigned, maximum 8-bit value

Memory Characteristics

The exact number of bits in a char is defined by the CHAR_BIT macro found in the <climits> header. While the standard requires a minimum of 8 bits, modern POSIX systems and the vast majority of architectures define CHAR_BIT as exactly 8 bits.

Extended Character Types

To support wider character sets and Unicode encodings that exceed the capacity of a standard 8-bit char, C++ provides several extended character types, each with specific literal prefixes:
// Size is implementation-defined (usually 16 or 32 bits)
wchar_t wide_char = L'Ω';       

// C++20: 8-bit UTF-8 character (underlying type is unsigned char)
char8_t utf8_char = u8'A';      

// C++11: 16-bit UTF-16 character (underlying type is uint_least16_t)
char16_t utf16_char = u'ñ';     

// C++11: 32-bit UTF-32 character (underlying type is uint_least32_t)
char32_t utf32_char = U'🌍';    
Master C++ with Deep Grasping Methodology!Learn More