char (C++)

char is the C++ type that stores a single character, such as 'A' or '?'. It is written with single quotes and actually holds a small integer (the character's code).

C++

Because a char is really a number under the hood, you can do arithmetic on it — for example 'A' + 1 gives the code for 'B'. A single char uses one byte.

Note the difference between single quotes for a char ('a') and double quotes for a string ("a").

Examples

C++

#include <iostream>

int main() {
    char grade = 'A';
    char next = grade + 1;
    std::cout << grade << " " << next << std::endl;
    return 0;
}

Output:

A B

Learn it in a lesson

See also

Back to the Dictionary