Strings as Arrays of Characters Not Ideal... Next Slide

Representing strings with arrays of characters presents some problems:

Errors

Example: Because strings are stored in arrays, it is possible to attempt to access locations outside of the memory allotted to the string:
char label[10] = "value";
label[-1] = 'a';   // Eeek!
label[200] = 'z';  // No such location here!


BU CAS CS - A String Class: Part I - Lab
Copyright © 1993-2000 by Robert I. Pitts <rip@bu.edu> All Rights Reserved.