Home > Backend Development > C#.Net Tutorial > What are escape characters in c language

What are escape characters in c language

青灯夜游
Release: 2019-01-15 09:08:47
Original
19523 people have browsed it

转义字符是一种特殊的字符常量,以反斜线"\"开头,后跟一个或几个字符(数字或字母);因为它具有不同于原有字符的特定含义,故称“转义”字符。

What are escape characters in c language

转义字符,顾名思义,它可以改变有用字符的意思,可以将一个数字或者字母常量的意思改变成某一个命令。它作用就是为了来表示常见的那些不能显示的ASCII字符,如C语言里的\0,\t,\n等。

C语言中所有的转义字符和其所对应的意义:

What are escape characters in c language

注:需要区分好斜杠"/" 与 反斜杠"\" ,不可以互换。

转义字符示例:

代码示例:使用\n,\',\",\?,\0看看效果。

#include<stdio.h>    
int main(){    
     int number=50;  
     printf("You\nare\nlearning\n\&#39;c\&#39; language\n\n\"Do you know C language\?\""); 
     printf("\n\nphp中文网\0(m.sbmmt.com)");   
return 0;  
}
Copy after login

输出:

What are escape characters in c language

可以看出在printf()中,只要遇见了‘ \n ’就会换行;‘ \' ’会输出单引号,‘ \" ’输出双引号,‘ \? ’输出问好;

‘ \0 ’代表空字符,是一个结束符。如例子中,当遇见‘ \0  ’时,无论其后面是否还存在内容,都会停止输出。

总结:以上就是本篇文章的全部内容,希望能对大家的学习有所帮助。

The above is the detailed content of What are escape characters in c language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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