转义字符的迷惑

flying_music 2016-05-06 05:05:01
转义字符有些是为了控制输出格式,比如换行,分页

有些是为了区分界定符和内容,比如单引号、双引号

但‘\?’是干什么的啊?为什么要对问号转义啊?而且好像不写转义直接写问号也是可以的啊

为什么要多转义一个问号\?
...全文
111 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-05-06
  • 打赏
  • 举报
回复
稍不注意,竟然让1楼抢了先。
赵4老师 2016-05-06
  • 打赏
  • 举报
回复
Trigraphs The source character set of C source programs is contained within the 7-bit ASCII character set but is a superset of the ISO 646-1983 Invariant Code Set. Trigraph sequences allow C programs to be written using only the ISO (International Standards Organization) Invariant Code Set. Trigraphs are sequences of three characters (introduced by two consecutive question marks) that the compiler replaces with their corresponding punctuation characters. You can use trigraphs in C source files with a character set that does not contain convenient graphic representations for some punctuation characters. Table 1.1 shows the nine trigraph sequences. All occurrences in a source file of the punctuation characters in the first column are replaced with the corresponding character in the second column. Table 1.1 Trigraph Sequences Trigraph Punctuation Character ??= # ??( [ ??/ \ ??) ] ??’ ^ ??< { ??! | ??> } ??- ~ A trigraph is always treated as a single source character. The translation of trigraphs takes place in the firsttranslation phase, before the recognition of escape characters in string literals and character constants. Only the nine trigraphs shown in Table 1.1 are recognized. All other character sequences are left untranslated. The character escape sequence, \?, prevents the misinterpretation of trigraph-like character sequences. (For information about escape sequences, see Escape Sequences.) For example, if you attempt to print the string What??! with this printf statement printf( "What??!\n" ); the string printed is What| because ??! is a trigraph sequence that is replaced with the | character. Write the statement as follows to correctly print the string: printf( "What?\?!\n" ); In this printf statement, a backslash escape character in front of the second question mark prevents the misinterpretation of ??! as a trigraph.
小灸舞 2016-05-06
  • 打赏
  • 举报
回复
主要是来防止trigraphs

The question mark escape sequence \? is used to prevent trigraphs from being interpreted inside string literals: a string such as "??/" is compiled as "\", but if the second question mark is escaped, as in "?\?/", it becomes "??/"

参考:http://en.cppreference.com/w/cpp/language/escape
第0章 一些你可能正感到迷惑的问题 1 0.1 操作系统是什么 1 0.2 你想研究到什么程度 2 0.3 写操作系统,哪些需要我来做 2 0.4 软件是如何访问硬件的 2 0.5 应用程序是什么,和操作系统是如何 配合到一起的 3 0.6 为什么称为“陷入”内核 4 0.7 内存访问为什么要分段 4 0.8 代码中为什么分为代码段、数据段? 这和内存访问机制中的段是一回事吗 6 0.9 物理地址、逻辑地址、有效地址、线性 地址、虚拟地址的区别 11 0.10 什么是段重叠 12 0.11 什么是平坦模型 12 0.12 cs、ds这类sreg段寄存器,位宽是 多少 12 0.13 什么是工程,什么是协议 13 0.14 为什么Linux系统下的应用程序不能在 Windows系统下运行 14 0.15 局部变量和函数参数为什么要放在 栈中 14 0.16 为什么说汇编语言比C语言快 15 0.17 先有的语言,还是先有的编译器,第1个 编译器是怎么产生的 16 0.18 编译型程序与解释型程序的区别 19 0.19 什么是大端字节序、小端字节序 19 0.20 BIOS中断、DOS中断、Linux中断的 区别 21 0.21 Section和Segment的区别 25 0.22 什么是魔数 29 0.23 操作系统是如何识别文件系统的 30 0.24 如何控制CPU的下一条指令 30 0.25 指令集、体系结构、微架构、编程 语言 30 0.26 库函数是用户进程与内核的桥梁 33 0.27 转义字符与ASCII码 37 0.28 MBR、EBR、DBR和OBR各是 什么 39 第1章 部署工作环境 42 1.1 工欲善其事,必先利其器 42 1.2 我们需要哪些编译器 42 1.2.1 世界顶级编译器GCC 42 1.2.2 汇编语言编译器新贵NASM 43 1.3 操作系统的宿主环境 43 1.3.1 什么是虚拟机 44 1.3.2 盗梦空间般的开发环境,虚拟机 中再装一个虚拟机 45 1.3.3 virtualBox下载,安装 46 1.3.4 Linux发行版下载 46 1.3.5 Bochs下载安装 46 1.4 配置bochs 48 1.5 运行bochs 49 第2章 编写MBR主引导记录,让我们开始 掌权 52 2.1 计算机的启动过程 52 2.2 软件接力第一棒,BIOS 52 2.2.1 实模式下的1MB内存布局 52 2.2.2 BIOS是如何苏醒的 54 2.2.3 为什么是0x7c00 56 2.3 让MBR先飞一会儿 58 2.3.1 神奇好用的$和$$,令人迷惑的 section 58 2.3.2 NASM简单用法 60 2.3.3 请下一位选手MBR同学做 准备 60 第3章 完善MBR 65 3.1 地址、section、vstart浅尝辄止 65 3.1.1 什么是地址 65 3.1.2 什么是section 67 3.1.3 什么是vstart 68 3.2 CPU的实模式 70 3.2.1 CPU的工作原理 71 3.2.2 实模式下的寄存器 72 3.2.3 实模式下内存分段由来 76 3.2.4 实模式下CPU内存寻址方式 78 3.2.5 栈到底是什么玩意儿 81 3.2.6 实模式下的ret 84 3.2.7 实模式下的call 85 3.2.8 实模式下的jmp 92 3.2.9 标志寄存器flags 97 3.2.10 有条件转移 99 3.2.11 实模式小结 101 3.3 让我们直接对显示器说点什么吧 101 3.3.1 CPU如何与外设通信—IO 接口 101 3.3.2 显卡概述 105

64,646

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧