by randall » Apr 5, 2001 @ 8:43am
Using arrays are an easy way to manipulate like- data.<br><br>Imagine you have 10 phone numbers, and store each one in a seperate variable. you could use the names v_phone01, v_phone_02, v_phone_03, etc. But each time you wanted to add a new phone number, you would need a new variable. Everytime the program needed data, you would have to hardcode each variable:<br><br>cout << v_phone_01;<br>cout << v_phone_02;<br>cout << v_phone_03;<br>...<br>...<br>cout << v_phone_10;<br><br>Or, simply put it into an array: v_phone(x). It is much easier to search/add/remove/edit data in an array.<br><br>for (x=0; x<11; x++)<br>{<br>cout << v_phone(x) << "\n";<br>}<br><br>This is much more noticeable with large amounts of data. Imagine 100, 1000, 10000 phone numbers<br><br>I am sure there are a million typos in the code above, so I don't want to hear about how I forgot this-an-that. Hopefully I got the point across.<br><br><br>Last modification: randall - 04/05/01 at 05:43:47