Programming languages use variables to give you access to data in memory. So if you are going to store the data from the results . txt file in memory, it makes sense that you'll need to use lots of variables to access all the data, right?
But how many variables do you need?
Imagine the file just had three scores in it. You could write a program that read each of the lines from the file and stored them in variables called first score, second score, and third score:
The data in the f ile
Each line in the file gets a variable of its own.
But what if there were four scores in the file? Or five? Even worse, what if there were 10,000 scores? You'd soon run out of variable names and (possibly) memory in your computer, not to mention the wear and tear on your fingers.
Sometimes, you need to deal with a whole bundle of data, all at once. To do that, most languages give you the array.
Was this article helpful?