Home >Backend Development >C++ >How Do C Escape Sequences Represent Special Characters in String Literals?

How Do C Escape Sequences Represent Special Characters in String Literals?

Linda Hamilton
Linda HamiltonOriginal
2024-12-09 04:46:10954browse

How Do C   Escape Sequences Represent Special Characters in String Literals?

Escape Sequences in C String Literals

C provides escape sequences to represent special characters within string literals. The escape character, (backslash), is prefixed to specific characters to denote their literal interpretation.

Control Characters:

  • a Alert (bell)
  • b Backspace
  • t Horizontal tab
  • n Newline (line feed)
  • v Vertical tab
  • f Form feed
  • r Carriage return
  • e Escape (non-standard GCC extension)

Punctuation Characters:

  • `" Quoted double character
  • ' Apostrophe
  • ? Question mark (used to avoid trigraphs)
  • \ Backslash

Numeric Character References:

  • up to 3 octal digits
  • x any number of hex digits
  • u 4 hex digits (Unicode BMP, C 11 onwards)
  • U 8 hex digits (Unicode astral planes, C 11 onwards)

Example:

To create a string containing a null character (

The above is the detailed content of How Do C Escape Sequences Represent Special Characters in String Literals?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn