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

In C language, escape sequence

WBOY
Release: 2023-08-29 17:17:13
forward
1241 people have browsed it

In C language, escape sequence

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

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

char ch = &#39;</p><p>&#39;;
Copy after login

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

char ch = &#39;\1&#39;;
Copy after login

下表列出了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);
}
Copy after login

输出

Test for tabspace and a newline
will start here
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template