Recognize a C string as characters ending with a null character.
Understand the concept
A string literal used to initialize an array includes a terminating null byte. strlen counts characters before that byte, while sizeof the array includes all its storage. The string.h header declares strlen.
Read the example
The complete program appears below. Read it first, predict the output, then run it.
Expected output
Length: 3, storage: 4
Practise
Change the text to Pune. Predict both numbers before running.
Common mistake
Reserve space for the null terminator. A character array without a terminator is not safe to pass to functions expecting a C string.