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?

4

4 Answers

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

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.

'\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.

1

space is represented in String as "\s", probably space is represented as '\s' as a character

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy