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 |
---|---|
\a | alert (bell) character |
\\ | backslash |
\b | backspace |
\? | question mark |
\f | form feed |
\' | single quote |
\n | new line |
\" | double quote |
\r | carriage return |
\ooo | octal number |
\t | horizontal tab |
\xhh | hexadecimal number |
\v | vertical 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) |
---|---|
A | 65 |
B | 66 |
P | 80 |
Q | 81 |
Z | 90 |
b | 98 |