C语言中的一些斜杠/反斜杠

斜杠与反斜杠

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

除号是 / 3/5 = 0

转义字符

C语言中用转义字符(Escape Character)即以反斜杠(\)开头的字符序列来描述特定的控制字符。
常用的转义字符:
‘\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’转义字符会把终端界面的输出光标移至当前行的最开头出

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

输出结果

hello world!

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
#include<stdio.h>
int main()
{
	printf("123456\b");
	return 0;
}

输出结果

123456

注释

C/C++:

//   /*    */

python

#

html:

<!--    -->

Java

//   /*   */   /**     */

注释是用两个斜杠表示

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

还有一种注释,是用斜杠加上星号来表示的

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

输出结果均为

123456

Windows系统中的文件索引

Windows系统中的文件索引使用反斜杠来表示上下级关系,例如
“C:\Users\李白\AppData\Local”

Python中打开文件

在python中,打开文件时,传入文件绝对路径,用的是斜杠来索引,例如

open('C:/Users/Desktop')

html中的斜杠反斜杠

## Java中的文件索引字符串
D:\\file\\a.txt
D:/file/a.txt

暂时只想到这么多,再碰到会继续补充

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值