Is spacebar a character?

80,798

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.

Share:
80,798
EngGenie
Author by

EngGenie

Updated on August 11, 2021

Comments

  • EngGenie
    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
      Oded over 11 years
      space is a character. The spacebar is on your keyboard and you use it to produce the space character.
    • Don Roby
      Don Roby over 11 years
      If you want help with your code, show us your code please.
    • Oded
      Oded over 11 years
      \0 is an escape sequence for the null value that in C string signifies the end of the string. It is a way to put null in a string and is coded into a single character.
    • David Ranieri
      David Ranieri over 11 years
      Both spacebar and NUL ('\0') are 1 byte chars
  • David Ranieri
    David Ranieri over 11 years
    I think that '\0' == 0 in ALL implementations
  • Bob__
    Bob__ over 2 years
    Please note that this question is tagged as C language. The character representing a space is, well, ' '.