标签:
| 转义字符 | 意义 | 阿斯科马值( ASCII)(十进制) |
| \a | 响铃BEL | 007 |
| \b | 退格(BackSpace) ,将当前位置移到前一列(删除) | 008 |
| \f | 换页(FF),将当前位置移到下页开头 | 012 |
| \n | 换行(LF) ,将当前位置移到下一行开头 | 010 |
| \r | 回车(CR) ,将当前位置移到本行开头 | 013 |
| \t | 水平制表(HT) (跳到下一个TAB位置) | 009 |
| \v | 垂直制表(VT) | 011 |
| \\ | 代表一个反斜线字符‘‘\‘ | 092 |
| \‘ | 代表一个单引号(撇号)字符 | 039 |
| \" | 代表一个双引号字符 | 034 |
| \0 | 空字符(NULL) | 000 |
| \ddd | 1到3位八进制数所代表的任意字符 | 三位八进制 |
| \xhh | 1到2位十六进制所代表的任意字符 | 二位十六进制 |
现在一一测试:
转义字符 \a |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
<span style="color:#33cc00;">#include <stdio.h>
#include <stdlib.h>
int main()
{
printf( "\a" );
return 0;
}</span>运行,可以听到 嘟 的一声。个人觉得这个转义字符最有魅力了~
或者你可以这样子:
<span style="color:#33cc00;">#include <stdio.h>
#include <stdlib.h>
int main()
{
char beep = 7;
printf( "%c", beep );
return 0;
}</span>
或者这样子:
<span style="color:#33cc00;">#include <stdio.h>
#include <stdlib.h>
int main()
{
char beep = '\a';
printf( "%c", beep );
return 0;
}</span><span style="color:#33cc00;">#include <stdio.h>
#include <stdlib.h>
int main()
{
char beep = '\007';
printf( "%c", beep );
return 0;
}</span>
甚至这样子:
<span style="color:#33cc00;">#include <stdio.h>
#include <stdlib.h>
int main()
{
char beep = '\07';
printf( "%c", beep );
return 0;
}</span>这样子:
<span style="color:#33cc00;">#include <stdio.h>
#include <stdlib.h>
int main()
{
char beep = '\7';
printf( "%c", beep );
return 0;
}</span>
)这么多种!是啊,C语言变幻莫测啊。以上小程序效果都一样。
转义字符 \b |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-

转义字符 \f |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
#include <stdio.h>
#include <stdlib.h>
int main()
{
char AnotherPage = 0xa;/* 0xa = 012 ,'\f' */
int PageNum = 10;
printf( "-|-|-|-" );
printf( "%c-", AnotherPage );
return 0;
}
运行结果是这样的:
-|-|-|-
-
怎么跟换行\n效果一样了?
如果选择直接输出这个走页符现象更奇葩了:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf( "\f" );
return 0;
}转义字符 \r |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf( " + B = C\rA" );/* There are two space between symbol " and symbol + ,when printf receive \r, A go to the first space ! */
return 0;
}
这个感觉不错~
转义字符 \v |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf( "\v" );
return 0;
}
转义字符 \\ \‘ \" |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
我觉得这个 \ 极其不单纯。
转义字符 \0 |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
<span style="color:#3366ff;">#include <stdio.h>
#include <stdlib.h>
int main()
{
printf( "A" );
printf( "\0" );
printf( "B" );
return 0;
}</span>C Language Study - <转义字符> " \a is fantastic ! "
标签:
原文地址:http://blog.csdn.net/oimchuan/article/details/44783839