Character datatype in C

The character data type in C, stores a single character within a single quotation mark and requires a single byte of memory in almost all compilers.

The char keyword in c is used to declare or define the character in C. It can hold alphabet, digits from 0 to 9 and special symbols and the format specifier for character is %c.

Read More: Data Types in Introduction

Let us understand this through a program :-

#include<stdio.h>
#include<conio.h>
int main()
{
    char x='a', y='2', z='*';
    
    printf("\n%c is an alphabet",x);
    printf("\n%c is a digit character",y);
    printf("\n%c is a special symbol character",z);
    
    getch();
    return 0;
}    

 The output of the following will be code :-

a is an alphabet
2 is a digit character
* is a special symbol character

We can calculate size, limit of the char data type can hold in C using sizeof() operator  and macros.

#include<stdio.h>
#include<conio.h>
#include<limits.h>
int main()
{
    printf("SIZE OF CHAR DATA TYPE IN BYTE      :    %d\n",sizeof(char));
    printf("SIZE OF CHAR IN BITS    :   %d\n", CHAR_BIT);
    printf("CHAR DATA TYPE, MAXIMUM VALUE CAN HOLD    :   %d\n", CHAR_MAX);
    printf("CHAR DATA TYPE, MINIMUM VALUE CAN HOLD    :   %d\n", CHAR_MIN);
 
    getch();
    return 0;
}    

Output of the following code :-

SIZE OF CHAR DATA TYPE IN BYTE     :    1
SIZE OF CHAR IN BITS    :   8
CHAR DATA TYPE, MAXIMUM VALUE CAN HOLD    :   127
CHAR DATA TYPE, MINIMUM VALUE CAN HOLD    :   -128

The character can be divided into two types : signed char and unsigned char

Type range (limit)
signed char -128 to 127
unsigned char 0 to 255