Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

char — a character integer type

char stores one byte. It is distinct from signed char and unsigned char; its signedness depends on the implementation.

Version: C23; repository compiler flag, production runtime not attested

Syntax

char name = 'A';

char is an integer type. sizeof(char) is always 1; a byte contains CHAR_BIT bits, at least 8, not necessarily exactly 8.

char, signed char, and unsigned char are distinct types. The implementation defines whether char has the range and behavior of signed char or unsigned char. <limits.h> provides CHAR_MIN and CHAR_MAX.

The constant 'A' has type int, although it can initialize char. The first null character (\0) marks the end of the string. It need not be the last element of the array that holds the string. One char need not hold a complete Unicode character.

Examples

#include <stdio.h>

int main(void)
{
    char letter = 'A';
    char text[] = "Hi";

    printf("%c\n", (int)letter);
    printf("%zu\n", sizeof letter);
    printf("%zu\n", sizeof text);
    return 0;
}

Result

A
1
3

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources