C char type

What is C char type

C char type is used to store single character, such as letter 'a', 'X' or sign letter '%'.

Internally the char type in C is stored as integer.

Example for char type

"A" is represented as decimal value 65


#include <stdio.h>
// ww w  .j av a 2  s.co m
main()
{
    char i = 65;
   
    printf("%c", i);
}

The code above generates the following result.

Escape char

Escaped characters are character which we cannot input directly from keyboard. For example, new line character. The following table lists the escaped characters we often use.

Escape sequence Value
\aalert (bell) character
\\backslash
\bbackspace
\?question mark
\fform feed
\'single quote
\nnew line
\"double quote
\rcarriage return
\ooooctal number
\thorizontal tab
\xhhhexadecimal number
\vvertical tab

Example for escaped char

Save Tab key into a char and then output.


#include <stdio.h>
 // www .  ja  v a 2 s .  c  om
int main()
{
    char tab='\t';
   
    printf("a%cb",tab);
   
    return 0;
}

The code above generates the following result.

Characters and ASCII Codes

Character ASCII Code (Decimal)
A65
B66
P80
Q81
Z90
b98




















Home »
  C Language »
    Language Basics »




C Language Basics
Data Types
Operator
Statement
Array