twitter
    Find out what I'm doing, Follow Me :)

How Do We Use The String?

The variable "name" is therefore a string which can hold up to 5 characters, since we need room for theNULL character, there are actually only four useful characters. To load something useful into the string, we have 5 statements, each of which assigns one alphabetical character to one of the string characters. Finally, the last place in the string is filled with the numeral 0 as the end indicator and the string is complete. (A "define" would allow us to use "NULL" instead of a zero, and this would add greatly to the clarity of the program. It would be very obvious that this was a NULL and not simply a zero, we will simply print it out with some other string data in the output statement. The % is the output definition to output a string and the system will output characters starting with the first one in "name" until it comes to the NULL character, and it will quit. Notice that in the "printf" statement, only the variable name "name" needs to be given, with no subscript since we are interested in starting at the beginning. (There is actually another reason that only the variable name is given without brackets. The discussion of that topic will be given in the next chapter.)