Strings are a common data structure in C programs. While "string" is not a built-in type in the language, because they are so common and useful, there are conventions about strings that are part of the language and followed by all C compilers.
We have been using strings, almost from the very beginning:
printf("Hello World\n");
Such strings are called string constants. They are created and maintained by the compiler.
An obvious data structure for storing a string is and array, in particular, an array of characters:
char str[81];
As we did with arrays previously, we must declare the array of sufficient size to hold the most characters we expect to store in the string. However, a particular string may have fewer characters. So how do we indicate the end of a string? In C the '\0' is defined to be a null character.
Remember that str is a pointer and this pointer cannot be changed if you want to increment/decrement through the array.
Initialization is the same as in arrays and all of the following are valid.
char c[] = "abcd";
OR,
char c[50] = "abcd";
OR,
char c[] = {'a', 'b', 'c', 'd', '\0'};
OR,
char c[5] = {'a', 'b', 'c', 'd', '\0'};
char *c = "abcd";