0

i always hear about arrays and it makes sence to me but whats a tipical use for them may i pleas see an example because i dont understand why they eaven exisit

5
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by John A
0

ya but wouldnt u have to enter every piece of data individually wether they were conected or not in an array so whats the point of having them connected in the first place?

0

Are you in school? (let's assume you are for the moment) Do you have classmates? How many? And how many in the whole school? (let's use 1000)

Would you want to define a single variable for everyone's name, then another for address, city, current class, grades so far..... That's 1000 distinct variables for the name. Another 1000 for the addresses. Another 1000...

I wouldn't. But one variable for the name, one for the city, etc, as an array and you have all the students in the array and you can get the information easily from just a few variables.

0

>ya but wouldnt u have to enter every piece of data individually
No. You could use loops to fill in data, which would require very little code. Let me show you an example:

for (int i=0 ; i < ARRAY_LENGTH ; ++i) {
    cout << "Type in a number" << endl;
    cin >> array[i];
}

>whats the point of having them connected in the first place?
Mostly so that they're easy to modify with loops. Another good example is a char array:

char myString[] = "test";

Without arrays, you'd be coding that for a lot longer...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.