The reason strings are terminated by null characters is that string-manipulation functionsboth those that are built in and those you may choose to definegenerally have no way to know, in advance, how many characters there are in any given string. Those functions rely, instead, on null charactersserving as end-of-string markersto tell them when to stop as they work their way through the characters.
In particular, the output operator, <<
, relies on null
characters when it deals with strings.