理解问 --true 0 不是数字 0

Understanding ask --true 0 not digit 0

本文关键字:数字 --true      更新时间:2023-10-16

目前我正在阅读一本C++说明书,但我不明白以下内容:


作者对说,这是真正的0,而不是数字0。

所以也许任何人都可以澄清真正的 0 和数字 0 之间的区别是什么?

用作

字符串终止字符。 不要与字符 0 混淆,其 ASCII 值为 48。因此,当迭代以空结尾的 C 样式字符串时,当您将字符与 0 进行比较时,将产生 true ,但不会产生0

此语句

作者对\0说,这是真正的0,而不是数字0。

看起来模棱两可。

而且我认为有一个错字。与其不如''

我认为作者的意思是字符文字。例如,"0"是一个字符文本,表示数字 0,其内部表示形式是不同于 0 的代码。例如,对于 ASCII 代码,"0"具有内部表示 48 或 0x30(十六进制)。对于EBCDIC,"0"具有内部表示0xF0。

字符文本 '\0' 的内部表示确实为 0。"\0"是所谓的octal escape character literal。例如,'\010' 是十进制数 8 的八进制表示形式。

由于类型char属于算术类型,因此当在某些算术表达式中使用"\0"时,它确实具有值0,而"0"的值为0x30(对于ASCII)或0xF0(对于EBCDIC)或其他值,具体取决于所用平台中的符号编码系统。

是C++中的空字符,主要用于终止字符串等,

其中 as 0 是数字数字。

来自c-FAQ的明确解释,

C programmers must understand that NULL and 0 are interchangeable in pointer 
contexts, and that an uncast 0 is perfectly acceptable. Any usage of NULL (as 
opposed to 0) should be considered a gentle reminder that a pointer is involved;
programmers should not depend on it (either for their own understanding or the
compiler's) for distinguishing pointer 0's from integer 0's.
It is only in pointer contexts that NULL and 0 are equivalent. NULL should not be 
used when another kind of 0 is required, even though it might work, because doing
so sends the wrong stylistic message. (Furthermore, ANSI allows the definition of
NULL to be ((void *)0), which will not work at all in non-pointer contexts.) In
particular, do not use NULL when the ASCII null character (NUL) is desired. 
Provide your own definition
#define NUL ''
if you must.