0
Why we are usig array?
4 Respuestas
+ 1
as opposed to a list? I'm not sure what you're asking
+ 1
Arrays can store multiple values for a dataset.
See it as a variable containing more than one number.
ie
List[5] = {1,2,3,4,5}; //these 5 values are stored
Now remember array "place holders" start counting from 0.
So
cout<< List[0]; //this would display 1
cout<< List[1]; //this would display 2
cout<< List[2]; //this would display 3
cout<< List[3]; //this would display 4
cout<< List[4]; //this would display 5
To display the entire list you have to use a for-loop
for(int i=0; i<5; i++)
{
cout<<List[i]<<endl; //endl means newline
}
Output:
1
2
3
4
5
0
to use multiple numbers and not just one number or variable.
Think of an array as a list
0
you could imagine that in case of : x [5]; x is the shopping list with 5 items in it. But you must only remember where is the bloody shopping list 😊