在C编程语言中,字符集中有256个字符。整个字符集分为两部分,即ASCII字符集和扩展的ASCII字符集。但除此之外,还有一些其他字符也不是任何字符集的一部分,称为ESCAPE字符。

转义序列列表

\ a闹钟或哔哔声   
\ b退格
\ f换页
\ n新行
\ r \ n回车
\ t标签(水平)
\ v垂直标签
\\反斜杠
单引号
“双引号
\?问号
\ ooo八进制数
\ xhh十六进制数
\ 0空
转义字符的一些编码示例
// C program to illustrate
// \a escape sequence
#include <stdio.h>
int main(void)
{
    printf("My mobile number "
          "is 7\a8\a7\a3\a9\a2\a3\a4\a0\a8\a");
    return (0);
}

输出:

我的手机号码是7873923408。
// C program to illustrate
// \b escape sequence
#include <stdio.h>
int main(void)
{
    // \b - backspace character transfers
    // the cursor one character back with
    // or without deleting on different
    // compilers.
    printf("Hello Geeks\b\b\b\bF");
    return (0);
}

输出:

输出取决于编译器。
// C program to illustrate
// \n escape sequence
#include <stdio.h>
int main(void)
{
    // Here we are using \n, which
    // is a new line character.
    printf("Hello\n");
    printf("GeeksforGeeks");
    return (0);
}

输出:

你好
GeeksforGeeks
// C program to illustrate
// \t escape sequence
#include <stdio.h>
int
main(void)
{
    // Here we are using \t, which is
    // a horizontal tab character.
    // It will provide a tab space
    // between two words.
    printf("Hello \t GFG");
    return (0);
}

输出:

你好GFG

转义序列“\ t”经常用于基于循环的模式打印程序。

// C program to illustrate
// \v escape sequence
#include <stdio.h>
int main(void)
{
    // Here we are using \v, which
    // is vertical tab character.
    printf("Hello friends");
    printf("\v Welcome to GFG");
    return (0);
}

输出:

你好朋友
欢迎来到GFG
// C program to illustrate \r escape
// sequence
#include <stdio.h>
int main(void)
{
    // Here we are using \r, which
    // is carriage return character.
    printf("Hello fri \r ends");
    return (0);
}

输出:(取决于编译器)

结束 
// C program to illustrate \\(Backslash)
// escape sequence to print backslash.
#include <stdio.h>
int main(void)
{
    // Here we are using \,
    // It contains two escape sequence
    // means \ and \n.
    printf("Hello\\GFG");
    return (0);
}

输出:(取决于编译器)

你好\
GFG 

说明:它包含两个转义序列意味着它在打印后\编译器读取下一个\作为新行字符即\ n,它在下一行打印GFG

// C program to illustrate \' escape
// sequence/ and \" escape sequence to
// print single quote and double quote.
#include <stdio.h>
int main(void)
{
    printf("\' Hello Geeks\n");
    printf("\" Hello Geeks");
    return 0;
}

输出:

'你好极客
“你好极客
// C program to illustrate
// \? escape sequence
#include <stdio.h>
int main(void)
{
    // Here we are using \?,  which is
    // used for the presentation of trigraph
    // in the early of C programming. But
    // now we don't have any use of it.
    printf("\?\?!\n");
    return 0;
}

输出:

??!
// C program to illustrate \OOO escape sequence
#include <stdio.h>
int main(void)
{
    // we are using \OOO escape sequence, here
    // each O in "OOO" is one to three octal
    // digits(0....7).
    char* s = "A\0725";
    printf("%s", s);
    return 0;
}

输出:

答:5

说明:这里000是一到三个八进制数字(0 ... .7)意味着在\和最大三个之后必须至少有一个八进制数字。这里的072是八进制表示法,首先它被转换为十进制表示法,即ASCII值char':'。在\ 072的地方有:并且输出是A:5。

// C program to illustrate \XHH escape
// sequence
#include <stdio.h>
int main(void)
{
    // We are using \xhh escape sequence.
    // Here hh is one or more hexadecimal
    // digits(0....9, a...f, A...F).
    char* s = "B\x4a";
    printf("%s", s);
    return 0;
}

输出:

BJ

说明:这里hh是一个或多个十六进制数字(0 ... .9,a ... f,A ... F)。\ xHere'\ x4a'是十六进制数后可以有多个十六进制数,它是一个单个字符。首先它将转换为十进制表示法,它是char'J'的ASCII值。因此,在\ x4a的位置,我们可以写J.所以输出是BJ。

C中的转义序列-IDC帮帮忙