jeremyhansen / rooksguide-cplusplus

The Rook's Guide to C++
44 stars 12 forks source link

Chapter 11 errata for array representation of strings #20

Open LeviSchuck opened 10 years ago

LeviSchuck commented 10 years ago

Figure 11.1 shows a string in array format, I believe that it should also include an 11th cell which has \0 or \NUL or something like that. (preferably \0).

Although a very tiny detail, we shouldn't make strings magical by hiding how they tell the end of a string.

For example, in C-languages, a string is usually null terminated, though in other languages like python, the first memory cell is usually a word (int32 or int64 depending on platform) which has the count for how large the rest of the sequence of bytes / characters / entries will be. Note, that this is not exactly how python works, but is the general concept for most languages that are more recent.

However, an iterator will not go over this "11th" cell.

We mention arrays and such, but never show that a string can actually be accessed like an array with the operator [] that strings have.