Node:Conventions and declarations, Next:Initializing strings, Previous:Strings, Up:Strings
Conventions and declarations
Do not confuse strings in C with individual characters. By convention,
individual characters are enclosed in single quotes, like this:
'a'
, and have the variable type char
. On the other hand,
string values are enclosed in double quotes, like this:
"abcdefg"
. String variables are either arrays of type
char
or have the type "pointer to char
", that is,
char *
.
Conceptually, a string is an array of characters (type char
). In
C, string variables can theoretically be of any length, unlike languages
such as Pascal where strings hold a maximum of 255 characters. However,
the length of the string value is determined by the position of the
first null character ('/0'
) in the string. Even though a string
variable might be 32,000 characters long, or longer, if the null
character first appears at position 5 in the character array, the string
value is considered to be of length 5 (and contains the characters in
positions 0 through 4, in sequence). You will rarely need to consider
this end marker, as most functions in C's string library add it or
remove it automatically.