`char` — C++ Keyword

`char` — C++ Keyword

The char keyword in C++: a character type large enough to hold any member of the basic character set.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

char

The basic character type. Large enough to hold any character in the implementation's basic character set. May be signed or unsigned — implementation-defined.

Syntax

char c;
char c = 'A';
const char* s = "hello";

Example

#include <print>
#include <cctype>

int main() {
    char c = 'G';
    std::println("{}", c);                         // G
    std::println("{}", static_cast<int>(c));       // 71 (ASCII)
    std::println("{}", std::toupper(c));            // 71 (uppercase of 'G' is still 'G')

    // Iterating a C-string
    const char* word = "hello";
    for (const char* p = word; *p != '\0'; ++p) {
        std::print("{} ", static_cast<int>(*p));   // 104 101 108 108 111
    }
    std::println();
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}