在C语言中,字符集中有256个字符。整个字符集分为两部分,即ASCII字符集和扩展ASCII字符集。但除此之外,还有一些其他字符不属于任何字符集,称为转义字符。
null
转义序列列表
转义字符的一些编码示例
// C program to illustrate // a escape sequence #include <stdio.h> int main( void ) { printf ( "My mobile number " "is 7a8a7a3a9a2a3a4a0a8a" ); return (0); } |
输出:
My mobile number is 7873923408.
// C program to illustrate // escape sequence #include <stdio.h> int main( void ) { // - backspace character transfers // the cursor one character back with // or without deleting on different // compilers. printf ( "Hello GeeksF" ); return (0); } |
输出:
The output is dependent upon compiler.
// C program to illustrate // escape sequence #include <stdio.h> int main( void ) { // Here we are using , which // is a new line character. printf ( "Hello" ); printf ( "GeeksforGeeks" ); return (0); } |
输出:
Hello GeeksforGeeks
// C program to illustrate // escape sequence #include <stdio.h> int main( void ) { // Here we are using , which is // a horizontal tab character. // It will provide a tab space // between two words. printf ( "Hello GFG" ); return (0); } |
输出:
Hello GFG
转义序列“”在基于循环的应用程序中非常常用 图案打印程序。
// 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); } |
输出:
Hello Friends Welcome to GFG
// C program to illustrate // sequence #include <stdio.h> int main( void ) { // Here we are using // is carriage return character. printf ( "Hello fri ); return (0); } |
输出:(取决于编译器)
ends
// 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 . printf ( "Hello\GFG" ); return (0); } |
输出:(取决于编译器)
HelloGFG
说明: 它包含两个转义序列,这意味着它在打印后,编译器将下一个作为新行字符读取,即。,在下一行打印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" ); printf ( "" Hello Geeks" ); return 0; } |
输出:
' Hello Geeks " Hello Geeks
// 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 ( "??!" ); 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 725" ; printf ( "%s" , s); return 0; } |
输出:
A:5
说明: 这里000是一到三个八进制数字(0…7),意味着后面必须至少有一个八进制数字,最多三个。这里072是八进制表示法,首先将其转换为十进制表示法,即字符“:”的ASCII值。在72的位置有:和输出是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 = "Bx4a" ; printf ( "%s" , s); return 0; } |
输出:
BJ
说明: 这里hh是一个或多个十六进制数字(0…9,a…f,a…f)。x之后可以有多个十六进制数。这里的“x4a”是一个十六进制数,是一个字符。首先,它将被转换成十进制表示法,它是字符“J”的ASCII值。所以在x4a的位置,我们可以写J,所以输出是BJ。
本文由 比沙尔·库马尔·杜比 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END