转义字符( \\’ \\” \\? \\\\ )的ascii码值是否与不转义之前相同
标准中定义的只有:\\a \\b \\f \ \\r \\t \\v \\\\ \\\u0026#39; \\" \\? \nn \\xhh这些转义字符对应的ASCII码可以参考这里:Escape sequences in C其余的都是未定义的行为。\\?确实是0x3F,等同于“?”,但不是说所有以"\\"开头的转义字符的ASCII码值都等于后面的那个字符的ASCII码值。甚至,在不同的编译器上,未定义的行为获得的结果都是不一样的。比如\u0026#39;\\e\u0026#39;在VS2008里是101,在GCC里是27.规范里的说法:Each of these escape sequences shall produce a unique implementation-defined value which can be stored in a single char object. The external representations in a text file need not be identical to the internal representations, and are outside the scope of this International Standard.不要去追究规范没有定义的内容。
■网友
刚才用c做了个实验,代码如下:char a = \u0026#39;?\u0026#39;;char b = \u0026#39;\\?\u0026#39;;printf("a is %d, b is %d\", a, b);打出来的结果:a is 63, b is 63这说明转义之后和转义之前本质是一样的。
推荐阅读
- Windows中文件名最大字符数
- json下面代码字符编码的规则是啥
- AWS或阿里云为何使用密钥对而不是单一字符串作为 Token
- Matlab中怎样在一个array中分别辨字符串和数值
- 编译原理:符号表中为啥要设计字符串表这样一种数据结构
- vb开发中字符串传参出现‘口’符
- 给出一个没有重复字母的字符串,怎样返回一个由同样的字母组成、按单词排序的字符串
- 知乎为啥选择直接删除右尖括号后的内容而不是将其转义
- MultiByteToWideChar和WideCharToMultiByte字符转换,新人求教
- 关于正则表达式的一个问题 ([0-9.\\-A-Za-z]+)为啥 . 前面不需要加转义符号