C17. C Escape Sequences

Escape Sequences
The \n code that we often use in format strings is called an escape sequence. Escape sequences enable strings to contain characters that would otherwise cause problems for the compiler, including nonprinting (control) characters and charac­ters that have a special meaning to the compiler (such as “). We'll provide a com­plete list of escape sequences later: for now. here's a sample:
Alert (bell)  \a
Backspace  \b
New line      \n
Horizontal tab \t
When they appear in printf format strings, these escape sequences represent actions to perform upon printing. Printing \a causes an audible beep on most machines. Printing \b moves the cursor back one position. Printing \n advances the cursor to the beginning of the next line. Printing \t moves the cursor to the next tab stop.

A string may contain any number of escape sequences. Consider the following printf example, in which the format string contains six escape sequences:
Executing this statement prints a two-line heading:
Item  Unit  Purchase 
Price   Date
Another common escape sequence is which represents the “ character. Since the “ character marks the beginning and end of a string, it can't appear within a string without the use of this escape sequence. Here's an example:
printf(“\”Hello!) ;
This statement produces the following output:
“Hello!” .

No comments: