Strings are terminated by null characters because 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 display function, printf
, relies on null
characters when it displays strings.