Exploring C strings
So far, we have explored individual characters and performed various operations on them. Dealing with individual characters is useful but more often, we will want to create words and sentences and perform operations on them. For this, we need a string of characters – or, more simply, we need a string.
An array with a terminator
A string is an array of characters with one special property. This special property is that the element after the last character of the C string must be a special character – the NUL
character, '/0'
. NUL
has a value of 0
. This character indicates the end of the string.
To implement a string, we must extend the concept of an array as a specially formatted array of characters; an array with an extra terminating NUL
character. The terminating character is sometimes called a sentinel. This is a character or condition that signals the end of...