C语言 空格键是字符吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13895729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:45:15  来源:igfitidea点击:

Is spacebar a character?

carraysstringchar

提问by EngGenie

Consider this line of text:

考虑这行文本:

First line of text.

第一行文字。

If a character array stringis used to load the first TEN characters in the array it will output as:

如果使用字符数组string加载数组中的前十个字符,它将输出为:

First lin'##代码##'

Firstcontains 5 letters, lincontains 3 letters. Where are the other two characters being used?

First包含5个字母,lin包含3个字母。其他两个字符在哪里使用?

Is \0considered two characters?

\0认为是两个字符?

Or is the space between the words considered a character, thus '\0` is one character?

或者单词之间的空格被认为是一个字符,因此 '\0` 是一个字符?

回答by Vladimir F

Yes, space is a character. In ASCII encoding it has code number 32.

是的,空间是一个字符。在 ASCII 编码中,它的代码编号为 32。

回答by Jonathan Leffler

The space between the two words has ASCII code 0x20 (0408, or 3210); it occupies one byte.

两个字之间的空格有ASCII码0x20(040 8,或32 10);它占用一个字节。

The null at the end of the string, ASCII code 0x00 (0 in both octal and decimal) occupies the other byte.

字符串末尾的空值,ASCII 码 0x00(八进制和十进制均为 0)占据另一个字节。

Note that the space bar is simply the key on the keyboard that generates a space character when typed.

请注意,空格键只是键盘上在键入时生成空格字符的键。

回答by sampson-chen

'\0'is the null-terminator, it is literally the value zero in all implementations.

'\0'空终止符,在所有实现中它实际上是零值。

'\0'is considered a single character because the backslash \means to escape a character. '\0'and '0'thus are both single characters, but mean very different things.

'\0'被视为单个字符,因为反斜杠\意味着转义字符'\0''0'因此都是单个字符,但意思完全不同的事情。

Note that space is represented by a different ascii value.

请注意,空格由不同的ascii 值表示