UMBC CMSC 202 CSEE | 202 | current 202

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


What are some advantages of C-style strings?

What are some disadvantages of C-style strings?

Last Modified: Monday, 28-Aug-2006 10:16:07 EDT