1. quick question about storing values in an array

Here's a code snippet i got from a book:

Code:
```/* Declare an array to hold expenses, and a counter variable */

float expenses[13];
int count;

int main(void)
{
/* Input data from keyboard into array */
for (count = 1; count < 13; count++)
{
printf("Enter expenses for month %d: ", count);
scanf("%f", &expenses[count]); <-------???
}```
Why is count inside the array expenses? can someone explain to me how the values are stored in the array expenses?

2. Originally Posted by houler
can someone explain to me how the values are stored in the array expenses?
Incorrectly.

The first element in the expenses array is 0, but the for loop starts storing something at expenses[1].

I'm not quite sure what you mean by "why is count in the array expenses?"

3. Originally Posted by itsme86
Incorrectly.

The highest element in the expenses array is 12, but the for loop will attempt to store something at expenses[13].
How is that? I can only see that it leaves out element 0.

edit: ignore this, post changed.

4. Originally Posted by Nyda
How is that? I can only see that it leaves out element 0.
Damn, you caught me before I could fix my mistake. My brain was thinking at the beginning of the array, but my fingers were thinking at the end of it

5. Originally Posted by itsme86
Incorrectly.

The first element in the expenses array is 0, but the for loop starts storing something at expenses[1].

I'm not quite sure what you mean by "why is count in the array expenses?"
Can you explain this part to me? I thought count was only used as a counter? why is it in between the braces?

scanf("%f", &expenses[count]);

i

6. It's a variable. It represents the index in the array where you want to store the value. Sure it's a counter variable, but each time through the loop you can use its value.
Code:
```{
int array[5];
int i;

for(i = 0;i < 5;++i)
{
array[i] = 1;
}
}```
...is the same thing as...
Code:
```{
int array[5];
int i;

array[0] = 1;
array[1] = 1;
array[2] = 1;
array[3] = 1;
array[4] = 1;

i = 5;
}```

7. Because think of it this way
First time through the loop
Code:
```for(count = 1; count < 13; count++)
{
scanf("%f",&expenses[count]);
/* count equals one */
/*count goes up one so count equals 2 now */
/*count continues to go up until it reaches 12 and then exits the loop */
/*so basically every time it goes through the loop it replaces count with the number */

}```

8. I get it. Thanks alot guys