当前位置:网站首页>今天浅讲一下转义字符【萌新版】
今天浅讲一下转义字符【萌新版】
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'
总结
- 可以看出来,在不同需要时可以用不同的方法输出字符
- 但存在字符转换或计算时,我们用转义字符要更加方便一些
边栏推荐
- 2022 latest Tiktok live broadcast monitoring (II) streaming media download in live broadcast room
- Explain exi interrupt through the counting experiment of infrared sensor
- SQL优化的N种方法
- 预分频值和自动重装值对中断频率的影响
- HCIA静态路由综合实验
- C语言——字符和字符串、算术运算符、类型转换
- Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
- Dynamic routing ofps protocol configuration
- Esp8266wi fi access cloud platform
- 7.16 written examination of Duoyi network
猜你喜欢
![[volatile principle] volatile principle](/img/d4/adb4b43aaccecd506065ce838c569e.png)
[volatile principle] volatile principle

Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay

Introduction to STM32 lesson 1

Nb-iot access to cloud platform

Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
![C language implementation of the small game [sanziqi] Notes detailed logic clear, come and have a look!!](/img/b9/ade9a808a3f6d24cd9825dc9b010c1.png)
C language implementation of the small game [sanziqi] Notes detailed logic clear, come and have a look!!

Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)

Lvs+keepalived project practice

(CF1691D) Max GEQ Sum

TCP的三次握手与四次挥手(简述)
随机推荐
TCP's three handshakes and four waves (brief introduction)
npm报错, Error: EPERM: operation not permitted, mkdir
SQL优化的N种方法
Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
静态路由综合实验
golang 实现 tcp-聊天室
NB-IOT联网通信
C语言——二维数组、指针
First knowledge of Web Design
Lora网关节点汇聚传感器数据
Lecture 3 - GPIO input / output library function usage and related routines
NAT(网络地址转化协议)
OSPF协议知识汇总
JVM面试题(面试必备)
Esp8266wi fi data communication
(super detailed version, don't know to comment at any time) codeforces round 804 (Div. 2) C the third problem
[Database Course Design] SQLSERVER database course design (student dormitory management), course design report + source code + database diagram
定时器中断实验
Codeforces Round #810 (Div. 2), problem: (B) Party
Golang中的错误处理