Is spacebar a character?
Solution 1
Yes, space is a character. In ASCII encoding it has code number 32.
Solution 2
The space between the two words has ASCII code 0x20 (0408, or 3210); it occupies one byte.
The null at the end of the string, ASCII code 0x00 (0 in both octal and decimal) occupies the other byte.
Note that the space bar is simply the key on the keyboard that generates a space character when typed.
Solution 3
'\0'
is the null-terminator, it is literally the value zero in all implementations.
'\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.
Note that space is represented by a different ascii value.
EngGenie
Updated on August 11, 2021Comments
-
EngGenie over 2 years
Consider this line of text:
First line of text.
If a character array
string
is used to load the first TEN characters in the array it will output as:First lin'\0'
First
contains 5 letters,lin
contains 3 letters. Where are the other two characters being used?Is
\0
considered two characters?Or is the space between the words considered a character, thus '\0` is one character?
-
Oded over 11 yearsspace is a character. The spacebar is on your keyboard and you use it to produce the space character.
-
Don Roby over 11 yearsIf you want help with your code, show us your code please.
-
Oded over 11 years
\0
is an escape sequence for thenull
value that in C string signifies the end of the string. It is a way to putnull
in a string and is coded into a single character. -
David Ranieri over 11 yearsBoth spacebar and NUL ('\0') are 1 byte chars
-
-
David Ranieri over 11 yearsI think that '\0' == 0 in ALL implementations
-
Bob__ over 2 yearsPlease note that this question is tagged as C language. The character representing a space is, well,
' '
.