herrcho said:
i'm in the course of learning C, and found these two words "string,
string literal" confusing me..
I'd like to know the difference between them.. Thank you
In C, a 'string' is an array of characters, the
last of which has a value of zero. A string can
have automatic, static, or allocated duration.
It can be defined to be modifiable or not
(see 'const').
A 'string literal' can appear in source code by
enclosing a character sequence in double quotes as in:
"Hello"
A 'string literal' represents a nonmodifiable string
in your program's memory space. (It occupies one more
character than those expressed between the quotes --
an implied terminator character ('\0') ). So the
string literal "Hello" occupies six bytes.
char s[20]; /* an array of twenty uninitalized characters */
strcpy(s, "Hello"); /* copy the characters of the string
literal to the array 's' ('strcpy()'
automatically adds the '\0' terminator) */
/* now the array 's' contains a string. (Note that if
a terminator character ('\0') is not an element of
the array, then it's not a string */
-Mike