斜杠与反斜杠
首先需要明白斜杠与反斜杠,
斜杠:/
反斜杠:\
除号是 / 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中的斜杠反斜杠
D:\\file\\a.txt
D:/file/a.txt