Arithmetic and Data Types - The character Data Type

Chapter chap4 section 10

The character data type invariably corresponds to a single byte or 8 bits of computer memory. A variable of character data type is declared using the keyword char . Input and output conversions are performed using the %c conversion code. This doesn't actually cause any conversion to take place, the bits in the variable are sent to the output or read from the input device unaltered. Character constants can be written by enclosing the character symbol in single quotes. Normally only a single character can appear between the character constant single quotes but the following conventions are understood.

NotationMeaning
'\''Single Quote
'\"'Double Quote
'\?'Question Mark
'\\'Backslash
'\a'Audible Signal (BEL)
'\b'Back space
'\f'Form feed (Page throw)
'\n'New line (line feed)
'\r'Carriage return
'\t'Tab
'\v'Vertical Tab

The above are called escape sequences. There are also escape sequences that allow the bit representations of characters in octal or hexadecimal notation. Typically these look like

	'\16' or '\xe'

the first being an octal escape sequence and the second being a hexadecimal escape sequence. Octal escape sequences may consist of up to three digits. Unlike octal constants there is no need for an initial zero. The use of character constants is illustrated in the following program.
main()
{
	char	x1='H',x2,x3='l';
	x2='e';
	printf("%c%c%c%c%c\n",x1,x2,x3,x3,'o');
}
producing the output
Hello
There are better ways of doing this.

Surprisingly char variables may be signed or unsigned . This only has an effect when char variables are being mixed with other variable types in arithmetic expressions. The implications will be discussed in the next section .