liveBook · Manning

Escape sequence

As explained in Modern C, Third Edition

An escape sequence is source-code notation beginning with a backslash that encodes a character or special value.

An escape sequence is source-code notation beginning with a backslash. In C, the Unicode escape \u followed by four hexadecimal digits encodes a code point inside a multibyte string. section 14.3

Encoding ä

The code point for “latin small letter a with diaeresis” is U+00E4, so a string can contain "\u00E4". A capital U followed by eight hexadecimal digits provides the larger form, but specialized contexts rarely require it. section 14.3

 #define VBAR "\u2502"      /**< a vertical bar character   */
 #define HBAR "\u2500"      /**< a horizontal bar character */
 #define TOPLEFT "\u250c"   /**< topleft corner character   */
 #define TOPRIGHT "\u2510"  /**< topright corner character  */

These C macro definitions use Unicode escape sequences to name box-drawing characters such as vertical bars, corners, and horizontal bars. section 14.3

Keep these distinctions in mind:

  • Use \u followed by four hexadecimal digits for a code point within the 65,536-code-point range addressed by four digits. section 14.3
  • Treat the escape as encoded character data, not as a guarantee that ordinary string functions will count or search multibyte characters correctly. section 14.3

How Modern C, Third Edition covers it

How deep it goes
Defines \u and \U forms with examples, then stops short of general Unicode processing and string-function internals.
Examples
Uses ä, Unicode box-drawing macros, and graphical characters absent from ordinary keyboards.
What you can do after
Apply it via C string literals to represent Unicode characters when direct keyboard input is unavailable.
How it connects
Connects escape sequences to Unicode code points, multibyte strings, wide character strings, and locale-dependent character processing.

Also explained in

Compare how 6 books explain escape sequence →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.