Umm i just want to ask how to use an array and when to use them. I just cant get what my teacher is telling. Maybe someone can give me a new idea. That's all thanks :)
A good hint might be when you are naming your variables item1, item2, item3, ... Or if you recognize other patterns of repitition.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
an array can be defined as a collection of similar data types.
suppose you want to use say 10 to 20 integer variables in your program it would be difficult to declare 20 variables.instead of that you can declare an integer array of size 20.and accessing elements in the array is easy and efficient.ou can simply declare the array by int a[20];
a[0] refers to 1st element,a[1] refers to second element and so on......
similarly a 2-d array is an array of arrays. it is equivalent to a matrix in the sense that in a 2-d array elements are stored in the format of a matrix.
strings are nothing but array of charecters.ok this is just an amateur introduction to arrays.you can find many tutorials on arrays on the web.
just try google.
indianscorpion2
Junior Poster in Training
82 posts since May 2005
Reputation Points: 9
Solved Threads: 1
zyruz
Junior Poster in Training
60 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
#include <iostream>
using namespace std;
int main()
{
int array[] = {10,20,30,40,50};
for ( int i = 0; i < 5; ++i )
{
cout << "array[" << i << "] = " << array[i] << '\n';
}
return 0;
}
/* my output
array[0] = 10
array[1] = 20
array[2] = 30
array[3] = 40
array[4] = 50
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
> What did I do wrong??
Not look at the post dates to realise that the person you're replying to hasn't been to this board in the last 2 years.
Post a new question, don't just dig up threads from the graveyard.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395