Chapter Summary

A C string is a series of chars terminated by the null character, `\0'. A string can be stored in a character array. A string can also be represented with a string constant, in which the characters, aside from the null character, are enclosed in double quotation marks. The compiler supplies the null character. Therefore, "joy" is stored as the four characters j, o, y, and \0. The length of a string, as measured by strlen(), doesn't count the null character.

String constants can be used to initialize character arrays. In pre-ANSI C, only external and static arrays can be initialized, but ANSI C permits automatic arrays to be initialized, too. The array size should be at least one greater than the string length to accommodate the ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.