Lecture
(none),
UMBC, CMSC 202 Computer Science II, Spring 2007
CMSC 202 Computer Science II, Spring 2007, Section 010x
C-style strings
An array of characters
In C, we represent a "string" using an array of characters.
To treat the array as an actual string (like "Hello"),
the "null character", '\0', is stored as the last character
in the array to mark the end of the string. Such an
array of null-terminated characters is often referred to
as a "C-style" string.
The presence of the null character is a result of how
the array is used. It's still an arary
of characters.
C-string declarations
char string1[4] = "abc";
char string2[ ] = "abc";
char *stringp = "abc";
// but not this
char string3[ ] = {'a', 'b', 'c'};
C-style string functions
The C library provides several functions to handle and manipulate
C-style strings, including