CThe char Type

The char Type

char is C's smallest integer type, guaranteed by the standard to be exactly one byte in size (sizeof(char) is always 1, by definition). It is most often used to store a single character, but under the hood a char is really just a small integer, and it supports arithmetic like any other integer type.

char is a small integer
Characters and numbers are the same thing in C
Every character in C is represented internally by its numeric character code (ASCII on virtually all common platforms). The character `'A'` is simply the integer 65 stored in a one-byte variable. Because of this, you can freely mix `char` values into arithmetic expressions.

C
#include <stdio.h>

int main(void) {
    char c = 'A';
    printf("%c has code %d\n", c, c);

    char next = c + 1;              /* arithmetic on a char! */
    printf("next character: %c\n", next);

    for (char letter = 'a'; letter <= 'e'; letter++) {
        printf("%c ", letter);
    }
    printf("\n");
    return 0;
}
A has code 65
next character: B
a b c d e 
signed char vs unsigned char
Whether plain char is signed is implementation-defined
The C standard does not specify whether plain `char` behaves as a `signed char` or an `unsigned char` — that choice is left to each compiler and platform (GCC on x86-64 Linux typically makes it signed; some ARM platforms make it unsigned by default). This matters most when a `char` holds a value above 127: on a signed implementation it becomes negative, while on an unsigned implementation it stays positive. Code that relies on the sign behavior of plain `char` — for example, when doing byte-level arithmetic or comparing char values numerically — can behave differently across compilers and is a well-known source of portability bugs. When the sign matters, declare `signed char` or `unsigned char` explicitly instead of relying on plain `char`.

C
#include <stdio.h>

int main(void) {
    char c = 200;               /* out of signed char's positive range */
    unsigned char uc = 200;

    printf("plain char: %d\n", c);        /* implementation-defined result */
    printf("unsigned char: %d\n", uc);    /* always 200 */
    return 0;
}
Character literals vs string literals
'A' and "A" are very different things
A character literal like `'A'` (single quotes) is a single `char` value — the number 65. A string literal like `"A"` (double quotes) is an array of characters terminated by a hidden null byte (`\0`), so `"A"` is actually two bytes: the character `A` followed by the terminator. Mixing these up — for example, trying to store `"A"` in a `char` variable, or comparing a `char` against a string literal with `==` — is one of the most common beginner mistakes in C.

C
#include <stdio.h>

int main(void) {
    char letter = 'A';      /* one char, value 65 */
    const char *word = "A"; /* pointer to a 2-byte array: {'A', '\0'} */

    printf("sizeof('A') as used here holds one char\n");
    printf("strlen-equivalent length of \"A\" is 1, but it occupies 2 bytes\n");

    /* char letter2 = "A"; */  /* INVALID: cannot assign a string to a char */
    return 0;
}

Form

Type

Size

Example

Character literal

char / int

1 byte value

'A'

String literal

array of char (char[])

length + 1 for the null terminator

"A" is 2 bytes

  • char is guaranteed to be exactly one byte, typically used to store one character.

  • A char is really a small integer — you can perform arithmetic on char values.

  • Whether plain char is signed or unsigned is implementation-defined; use signed char/unsigned char explicitly when it matters.

  • 'A' (single quotes) is a single char value; "A" (double quotes) is a 2-byte array including a null terminator — never confuse the two.