Friday, July 29, 2016

C Basics - Escape Sequence in C

An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly.

Although it consists of two characters, it represents single character.

Each escape sequence has unique ASCII value.

Each and every combination starts with backslash (\).

The following are the white space characters allowed in C: Each escape sequence in the below table maps to a single character.
\a alarm (bell)
\b back space
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\’ single quote
\” double quote
\\ back slash
\? question mark
\nnn The character whose numerical value is given by nnn interpreted as an octal number. An octal escape sequence consists of \ followed by one, two, or three octal digits. The escape sequence \0 is a commonly used octal escape sequence, which denotes the null character, with value zero.
\xhh The character whose numerical value is given by hh interpreted as a hexadecimal number. A hex escape sequence must have at least one hex digit following \x, with no upper bound; it continues for as many hex digits as there are.

An escape sequence is regarded as a single character and is therefore valid as a character constant.



Related topics:
Tokens in C   |   Character Set in C   |   White Space Characters in C   |   Trigraph Characters in C   |   Extended Characters in C   |   Comments in C   |   Keywords in C   |   Identifiers in C   |   Declaration in C

List of topics: C Programming

No comments:

Post a Comment