next up previous contents index
Next: Arrays and Strings Up: Types Previous: Determining the range of   Contents   Index


The char type

char is a numerical type, but its main use is to represent characters, not numerical work. C provides a wide range of character literals which return the numerical value of a character (usually the ASCII code). Character literals are enclosed in apostrophes, for example:

  
char c = 'H';
will assign to c the numerical value of the character H. Since char is an integer type and C will convert between numerical types quite readily, the following are perfectly legal

  
int i = 'H';
double f = 'c';

i = 'K' * 67.57;
but probably not very useful. C also defines character literals for less convenient characters, such as newline and the tab character (these actually give an int rather than a char, but this difference is not normally important). The newline, horizontal and vertical tab and form-feed characters, together with the space character are known collectively as whitespace.


Table 1.3: Special character literals
literal meaning
\a alert (bell)
\b backspace
\f page-break (form-feed)
\n newline (line-feed)
\r carriage-return
\t horizontal tab
\v vertical tab
\" double-quote
\' apostrophe
\\ backslash
\ooo the character with numerical value ooo in octal
\xhh... the character with numerical value hh... in hexadecimal



next up previous contents index
Next: Arrays and Strings Up: Types Previous: Determining the range of   Contents   Index
CATAM admin 2010-02-23