C语言中一些特殊字符的输出

 

目录

 %的介绍     

斜杠与反斜杠

转义字符

%的介绍     

     int a=1;
1、printf(’’%d’’,a);//输出1

2、printf(’’%%d’’,a);//输出%d

3、printf(’’%%%d ‘’,a)//输出%1

C语言中,%也是转义符,%%相当于%

斜杠与反斜杠

首先需要明白斜杠与反斜杠,斜杠:/,反斜杠:\ 

转义字符

常用的转义字符:
‘\n’,换行
‘\r’,回车
‘\0’,空字符,通常用作字符串结束标志
‘\b’,退格

下面演示这四个常用转义字符的作用
1,正常打印,不用任何转义字符

#include<stdio.h>
int main()
{
pritnf("hello world!");
printf("hello world!");
return 0;
}

输出结果

hello world!hello world!

2,'\n’转义字符

#include<stdio.h>
int main()
{
pritnf("hello world!\n");
printf("hello world!");
return 0;
}

输出结果

hello world!
hello world!

 如果两行都加上了’\n’

#include<stdio.h>
int main()
{
pritnf("hello world!\n");
printf("hello world!\n");
return 0;
}

 输出结果

hello world!
hello world!

3,'\r’转义字符

#include<stdio.h>
int main()
{
	printf("hello world!\r");
	printf("I love you!");
	return 0;
}

输出结果

I love you!!

再看一个例子

#include<stdio.h>
int main()
{
	printf("123456\r");
	printf("7890");
	return 0;
}

 输出结果

789056

'\r’转义字符会把终端界面的输出光标移至当前行的最开头出

4,'\b’转义字符

#include<stdio.h>
int main()
{
	printf("hello world!\b");
	printf("I love you!");
	return 0;
}

 输出结果

hello worldI love you!

'\b’会将终端界面的输出光标前移一个元素

#include<stdio.h>
int main()
{
	printf("123456\b");
	printf("7890");
	return 0;
}

输出结果

123457890

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

互联网的猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值