When we declare and initialize a string array, there are a few more possibilities that must be understood. We will explore them now:
- We can declare an empty string—that is, a string with no printable characters—as follows:
charstring0[8] = { 0 };
string0 is an array of 8 elements, all of which are initialized to NULL, the nul character, or simply 0.
- Next, we can declare a string and initialize the array with individual characters, as follows:
charstring1[8] = { 'h' , 'e' , 'l' , 'l', 'o' , '\0' };
When doing this, we must remember to add the nul character, or '\0'. Note that even though the array is declared to have 8 elements, we have onlyinitialized six of them. This method is rather tedious.
- Thankfully, the creators of C have given us an easier way to initialize a...