O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. The array size should be at least one greater than the string length to accommodate the terminating null character. String constants can also be used to initialize pointers of type pointer-to-char.

Functions use pointers ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required