C string

From Wikipedia, the free encyclopedia

In computing, C strings are character sequences stored as one-dimensional character arrays and terminated with a null character ('\0', called NUL in ASCII). The name refers to the ubiquitous C programming language using this string representation, and is used elsewhere to distinguish this often-used representation from others.

The null-termination characteristic has historically created security problems related to the length of the string. If the null character is not added to the end of the string for some reason, any following non-related memory area is also 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. This problem can (and should) be prevented by appropriate error checking.

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 advanced "string" objects provided by the STL.

[edit] Trivia

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

[edit] See also

C programming language
Libraries: C standard library | glibc | Dietlibc | uClibc | Newlib
History: Criticism of the C programming language
Language Features: String | Syntax | Preprocessor | Variable types and declarations | Functions
Dialects: C++ | Objective-C
C and Other Languages: Compatibility of C and C++ | Operators in C and C++ | Comparison of Pascal and C | C to Java byte-code compiler