• Home
  • 1.4 Character Data Type

1.4 Character Data Type

View Categories

1.4 Character Data Type

< 1 min read

The char type is used to store a character value. In C, a character constant such as 'A' is represented by an integer value according to the execution character set.

#include <stdio.h>

int main()
{
    char ch = 'A';

    printf("Character: %c\n", ch);
    printf("Integer value: %d\n", ch);

    return 0;
}

Example Output #

Character: A
Integer value: 65

The numeric value shown for 'A' is typical of an ASCII execution character set.

Explanation #

The variable is declared as:

char ch = 'A';

A character constant is written using single quotes:

'A'

%c displays the value as a character:

printf("Character: %c\n", ch);

Since char is an integer type, its value can also participate in integer expressions. %d displays the integer value after the usual integer promotions:

printf("Integer value: %d\n", ch);

Character and Integer Representation #

Character Typical ASCII value
'0' 48
'1' 49
'A' 65
'B' 66
'a' 97
'b' 98
Space ' ' 32

The C language does not require ASCII specifically. The actual values depend on the execution character set.

A char occupies exactly 1 byte, although the number of bits in that byte is implementation-defined.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *