Char Star

Wiki spelling of "char *", how one spells "string" in CeeLanguage (and how string is often spelled in CeePlusPlus as well, despite the existence of the string class).

CharStars are, of course, null-terminated sequences of bytes--the representation of a string in C. Much C folklore centers around their care and feeding (and around how to avoid BufferOverflows and NonNullTerminatedStrings--both common sources of crashes in C/C++, not to mention popular targets of crackers.)

String literals in C/C++ do two things:

  1. Allocate space for the specified string (including a null terminator) and
  2. cause the address of said string (the char *) to be returned.
Interestingly enough, when initializing a structure, a string literal can be used to initialize both a "char *" member (in which case the structure member gets the address) or a "char [n]" member (in which case the string data gets copied - with surprising results if it doesn't fit.)

In the post-AnsiCee days (and in CeePlusPlus), this is more correctly spelled "const char *" or "char const *", as a string literal is presumed to be immutable. Depending on the environment, writing to a string literal may result in a SegmentationFault or similar error (or worse, UndefinedBehavior), as string literals may be put in ROM or in write-protected memory segments. Many compilers have a "writeable strings" option for compiling old C/C++ programs that assume that string literals are writeable.


EditText of this page (last edited March 18, 2004) or FindPage with title or text search