Literals

Each type can have values expressed as literals or constants, such as
234an int
23.4a float
'2'a char
013 an int written in octal (base 8), denoted by initial zero
0x14 an int written in hexadecimal (base 16), denoted by initial zero x
There are also string literals, but these do not match a C type directly. They can be stored in arrays of type char and must be terminated there with a null character (value zero). But direct assignment of strings is not allowed. Instead a library of string handling functions is provided.
      "hi there!"	-	a string

Escapes and control characters

It is possible to include control characters, such as the newline character and certain other problem characters, in string literals and character literals by using an escape sequence, written as the backslash character, \, followed by another character. below is a complete list of these escapes.
\"double quote
\'single quote
\\backslash
\0the null character, marks end of strings
\aalert
\bbackspace
\fform feed
\nthe newline character
\rthe return character
\ttab
\vvertical tab

It is actually possible to define any character as an octal or hexadecimal escape sequence:
'\013'carriage return in octal
'\x1a'control-z in hexadecimal


Exercises on this section.


Next.

Back to Contents page.