Null-terminated string

This is an old revision of this page, as edited by Ktracy (talk | contribs) at 00:42, 31 October 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computing, a C string is a character sequence stored as a one-dimensional character array and terminated with a null character ('\0', called NUL in ASCII). The name refers to the ubiquitous C programming language which uses this string representation.

In the C++ programming language, C strings are used in addition to another representation of character sequences, the std::string container found in the Standard Template Library (STL). Thus, it is important to differentiate between the traditional "C strings" and the more sophisticated "string" objects provided by the STL.

The null-termination characteristic has historically created security problems related to the length of the string. If the null character is not correctly accounted for, any following non-related memory area may also be processed as a part of the character sequence. This can lead to program crashes or leakage of program internal information to attackers or non-understanding users.

Trivia

C strings are exactly equivalent to the strings created by the .ASCIZ directive implemented by the PDP-11 and VAX macroassembly languages.

See also