码迷,mamicode.com
首页 > 其他好文 > 详细

C Language Study - <转义字符> " \a is fantastic ! "

时间:2015-03-31 22:19:01      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

C语言转义字符
转义字符 意义 阿斯科马值( 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;
}
技术分享原来他们是一对儿!!!<\f & \v > ......

技术分享

转义字符 \\ \‘ \" |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-

我觉得这个 \  极其不单纯。

转义字符 \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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!