The ASCII-Zero Character Array
Arrays in C++ have an inherent problem: You can never know, just by looking at the array, how many values are actually stored in it. Knowing the size of an array is not enough. That tells you how many values the array can hold, not how many it actually does hold.
The difference is like the difference between how much gas your car’s tank can hold and how much gas it actually has. Even if your tank holds 20 gallons, you still need a gas gauge to tell you how much is in it.
There are essentially two ways of keeping track of the amount of data in an array:
Keep a count of the number of values in a separateintvariable. This is the technique used by the ArrayDemo program. The code that reads the user input keeps track of the number of entries in nCount. The only problem is that the program has to pass nCount along to every function to which it has passed the nScores array. The array isn’t useful without knowledge of how many values it stores.
Use a special value in the array as an indicator of the last element used. By convention, this is the technique used for character arrays in C++.
One ASCII character in particular is not a legal character: ‘