Definitions
A string is a contiguous sequence of characters terminated by and including the first null character (written '\0'
and corresponding to the ASCII character NUL). In C, there are two types of strings: string, which is sometimes called byte string, and wide string. A byte string contains the type char
s as code units (one char
is at least 8 bits), whereas a wide string contains the type wchar_t
as code units.
A common misconception is that all char
arrays are strings, because string literals are converted to arrays during the compilation (or translation) phase. It is important to remember that a string ends at the first null character. An array or string literal that contains a null character before the last byte therefore contains a string, or possibly several strings, but is not itself a string. Conversely, it is possible to create a char
array that is not null-terminated and is thus not a string. char
is often used as integer when needing to save memory, for example when having an array of booleans.
The term pointer to a string is used in C to describe a pointer to the initial (lowest-addressed) byte of a string. In C, pointers are used to pass strings to functions. Documentation (including this page) will often use the term string to mean pointer to a string.
The term length of a string is used in C to describe the number of bytes preceding the null character. strlen
is a standardised function commonly used to determine the length of a string.
Read more about this topic: Memset
Famous quotes containing the word definitions:
“What I do not like about our definitions of genius is that there is in them nothing of the day of judgment, nothing of resounding through eternity and nothing of the footsteps of the Almighty.”
—G.C. (Georg Christoph)
“Lord Byron is an exceedingly interesting person, and as such is it not to be regretted that he is a slave to the vilest and most vulgar prejudices, and as mad as the winds?
There have been many definitions of beauty in art. What is it? Beauty is what the untrained eyes consider abominable.”
—Edmond De Goncourt (18221896)