当前位置:网站首页>今天浅讲一下转义字符【萌新版】
今天浅讲一下转义字符【萌新版】
2022-07-26 22:49:00 【helinliupi-何】
不加'\'输出字符,直接输出字符
#include<stdio.h>
int main()
{
printf("a");
return 0;结果:
结论:
- 可以看出,当我们想输出字符时,我们可以直接用printf输出。
- 当需要字符时,直接输出字符的方式更简单一点。
需要'\'输出转义字符
单纯输出字符:
#include<stdio.h>
int main()
{
printf("%c",'a');
return 0;
}结果:
结论:用转义字符输出与直接输出结果一样
转义字符用与计算:
#include<stdio.h>
int main()
{
printf("%c\n",'a');
printf("%c\n",'a'-32);
return 0;
} 结果:
结论:需要通过字符进行运算时,用转义字符要更方便一些
提示(a的ASCII码为97,A的ASCII码是65)
ASCII码对照表(参考)

可以看出我们可以利用计算机对每个字符对应的数字来计算出不同的字符
转义字符(8进制与16进制表达)
#include<stdio.h>
int main()
{
printf("%c\n",'\123'); //8进制
printf("%c\n",'\x33'); //16进制
return 0;
}结果:
结论:
- 第一个8进制的转义字符,计算为:1*8^2 + 2*8 + 3 = 115 对应ASCII码为s字符
- 第二个16进制转义字符,计算为:3*16 + 3 = 51 对应ASCII码为3字符--> '3'
总结
- 可以看出来,在不同需要时可以用不同的方法输出字符
- 但存在字符转换或计算时,我们用转义字符要更加方便一些
边栏推荐
- 识时务者常用网址大全
- OSPF protocol overview and basic concepts
- (史上最详细)Codeforces Round #805 (Div. 3)E. Split Into Two Sets
- 勤写标兵——云小井
- Static routing default routing VLAN experiment
- TreeSet集合存储元素的问题
- Simple application of rip V2 (V2 configuration, announcement, manual summary, ripv2 authentication, silent interface, accelerating convergence)
- 7.16 written examination of Duoyi network
- Codeforces Round #796 (Div. 2), problem: (1688C) Manipulating History
- Influence of pre frequency division value and automatic reload value on interrupt frequency
猜你喜欢

Dynamic routing rip protocol experiment

About unsafe problems such as fopen and strError encountered in vs2022 or advanced version running environment

二层封装技术(HDLC、PPP--PAP\CHAP、GRE)实验练习

三个整数从大到小排序(详细介绍多种方法)

Experiment of total connection and star topology of mGRE

Static comprehensive experiment (comprehensive exercise of static route, loopback interface, default route, empty interface, floating static)

RS-485 bus communication application

C语言——数据类型、基本数据类型的取值范围

HCIA (network elementary comprehensive experimental exercise)

HCIA基础知识(1)
随机推荐
(CF1691D) Max GEQ Sum
Can bus communication application
Nb-iot networking communication
OSPF basic configuration application (comprehensive experiment: interference election default routing area summary authentication -- interface authentication)
[Database Course Design] SQLSERVER database course design (student dormitory management), course design report + source code + database diagram
lvs+keepalived项目实战
[explain C language in detail] takes you to play with functions
ESP8266Wi-Fi数据通讯
Golang中的错误处理
NAT (network address translation protocol)
求解整数的每一位
Tim output comparison - PWM
静态路由综合实验
通过对射式红外传感器计次实验讲解EXTI中断
OSPF协议知识汇总
静态综合实验(静态路由、环回接口、缺省路由、空接口、浮动静态的综合练习)
Introduction to STM32 lesson 1
HCIA Basics (1)
Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
求解100~200之间的素数