Home  >  Article  >  Backend Development  >  In C language, escape sequence

In C language, escape sequence

WBOY
WBOYforward
2023-08-29 17:17:131102browse

In C language, escape sequence

许多编程语言支持一种称为转义序列的概念。当一个字符前面有一个反斜杠(\)时,它被称为转义序列,并且对编译器有特殊的意义。例如,下面的语句中的

是一个有效的字符,它被称为换行字符 −

char ch = &#39;</p><p>&#39;;

在这里,字符n之前有一个反斜杠(\),它具有特殊含义,即换行,但请记住反斜杠(\)只对一些字符具有特殊含义。以下语句在C编程中不会传达任何含义,将被视为无效语句−

char ch = &#39;\1&#39;;

下表列出了C编程语言中可用的转义序列 −

序号 转义序列及描述
1 \t

在文本中插入一个制表符。

2 \b

在文本中插入一个退格符。

3

在文本中插入一个换行符。

4 \r

在文本中插入一个回车符。

5 \f

在文本中插入一个换页符。

6 \’

在文本中插入一个单引号。

7 \”

在文本中插入一个双引号。

8 \

在文本中插入一个反斜杠。

示例

#include <stdio.h>
int main() {
   char ch1;
   char ch2;
   char ch3;
   char ch4;
   ch1 = &#39;\t&#39;;
   ch2 = &#39;</p><p>&#39;;
   printf( "Test for tabspace %c and a newline %c will start here", ch1, ch2);
}

输出

Test for tabspace and a newline
will start here

The above is the detailed content of In C language, escape sequence. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete