If I have an array like a[100]
and I start from 1
or 0
. When I declare int a[100]
, how long is my array?
It always starts counting from 0
? If yes it will be an array with 101
spaces.
#include <iostream>
using namespace std;
int main()
{
float time[20]; //
int a, first = 20, y, x;
for (x = 1; x < 21; x++) {
cout << "Enter the time of the person number " << x << " : ";
cin >> time[x];
}
for (y = 1; y < 20; y++) {
if (time[y] < first) {
first = time[y];
a = y;
}
}
getchar();
cout << "The person " << a << " was the faster.";
cout << time[1];
getchar();
return 0;
}
Here it starts from 1
.
And if I change it will start from 0
.
for (x=0;x<21;x++)
for (y=0;y<20;y++)
And why is much better to start from 0
?