The type of string
used in the C
programming language and most languages like it. This type of string is just a general concept and is not really hardwired into the language (although it is what the standard library
expects in its input
functions, and the double-quote operators use it-- but more on that later) but rather based simply on convention
. It is named "C string" because it was first used in C, but it doesn't necessarily have
to be a C thing. Like most things related to C, the concepts behind it give you an extremely high degree of flexibility
as well as an environment where you can bugger things up rather horribly.
A C string (in any language) is stored in memory as a series of bytes representing characters (in C, this is a char array). The characters to be used begin at the first address possible (in C, address zero) and continue indefinitely. The end of the string is marked by a null terminator, a byte set equal to zero. (Null chars should be referred to in C as '\0'.) So when printf or cout is passed a string, it simply bangs everything out character by character until it reaches a null character, and then it stops.
If you are screwing with strings by hand in C, you need to be very aware of that null character, and make sure you don't accidentally leave it out. You also need to be aware that a four-letter string actually contains five characters because of the '\0'.
This is, by the way, the only difference in C between single quotes and double quotes when giving a series of chars; namely, the single chars are the literal, raw values of the chars, and the double quotes actually create a full C string with a null terminator. Thus 'k' is a char, whereas "k" is a 2-char array containing a k and a \0.
See also Pascal string