Escape Sequence


It's a combination of characters that has a meaning other than the literal characters contained therein.

Motivation

Consider this program:

C
#include <stdio.h>
int main() {
  printf("Hello
world!");
	return 0;
}

It's not valid C, because a string literal can't span multiple source lines. The solution is to print the newline character by using its numerical value (0x0A in ASCII).

C
#include<stdio.h>
int main() {
  printf("Hello,%cworld!", 0x0A);
  return 0;
}

This only works when the machine uses the ASCII encoding, it may not work on other encodings with a different value for the new line character. It's also not a good solution because it uses the semantics of printf.

The solution C came up was to use the backslash \ as a escape character. The character after the backslash defines the interpretation of the escape sequence.

Examples