Weird Array Issue

So I wrote a code that creates arrays each containing 7 values. I made Arduino read the values from humidity and heat sensors and write them to these arrays hour by hour.

But when I print the values from arrays to the Serial Monitor, I see the seventh integer of humidity array as "19995" and then "-25573", then "-5602" goes like that... Why is it not "0" like others?

And it is always the seventh integer...Very weird.

int heatArray[7] = {0,0,0,0,0,0,0}; 
int humidityArray[7] = {0,0,0,0,0,0,0}; 

switch (time) {
  case (1): //save the values when launched.
    heatArray[1] = heat;
    humidityArray[1] = humidity;
  break;
  case (2):  // //save the values after an hour.
    heatArray[2] = heat;
    humidityArray[2] = humidity;
  break;

  case (3):  // save the values after 2 hours.
    heatArray[3] = heat;
    humidityArray[3] = nem;
  break;

  case (4): // save the values after 3 hours.
    heatArray[4] = sicaklik;
    humidityArray[4] = humidity;
  break;

  case (5):  //save the values after 4 hours.
    heatArray[5] = heat;
    humidityArray[5] = humidity;
  break;

  case (6):  //save the values after 5 hours.
    heatArray[6] = heat;
    humidityArray[6] = humidity;
break;

  case (7):  // save the values after 6 hours.
    heatArray[7] = heat;
    humidityArray[7] = humidity;
    time= 0; // Resets time, starts from beginning.
break;
}

Serial.print("Heat: ");
Serial.print(heatArray[1]);
Serial.print(" ");
Serial.print(heatArray[2]);
Serial.print(" ");
Serial.print(heatArray[3]);
Serial.print(" ");
Serial.print(heatArray[4]);
Serial.print(" ");
Serial.print(heatArray[5]);
Serial.print(" ");
Serial.print(heatArray[6]);
Serial.print(" ");
Serial.println(heatArray[7]);
Serial.println(" ");
Serial.print("Humidity: ");
Serial.print(humidityArray[1]);
Serial.print(" ");
Serial.print(humidityArray[2]);
Serial.print(" ");
Serial.print(humidityArray[3]);
Serial.print(" ");
Serial.print(humidityArray[4]);
Serial.print(" ");
Serial.print(humidityArray[5]);
Serial.print(" ");
Serial.print(humidityArray[6]);
Serial.print(" ");
Serial.print(humidityArray[7]);
Serial.println(" ");
Serial.print("Time passed:");
Serial.println(time);

I omitted unnecessary parts of the code. Please tell me whether I used the Array command right or wrong. What's causing this issue?

Arrays start with 0, not 1. The first position in an array is 0 and seventh is 6. When you call 7, it is calling something from the memory outside the array, and who knows what that is.

BTW, take a look at for loops. They're quite useful.

Oh and one more thing. Aren't the arrays are zero indexed? So let's suppose I want to have an array with 7 items in it. Then shouldn't I need to write this: ?!?

heatArray[6] ={value1,value2,value3,value4,value5,value6,value7}

As far as understand Arrays:

heatArray[0] equals to value1 heatArray[1] equals to value2 heatArray[2] equals to value3 heatArray[3] equals to value4 heatArray[4] equals to value5 heatArray[5] equals to value6 heatArray[6] equals to value7

But when I state that I want 6 items in an Array, then type 7 items in curly bracket, Arduino warns me: "too many initializers"... What's going on here? I'm confused.

heatArray[6] ={

Seven items?

Yes, they are zero indexed, but index 0 also counts. If you count 0, 1, 2, 3, 4, 5, 6 you'll count 7 items. So declare it:

heatArray[7] ={value1,value2,value3,value4,value5,value6,value7};

(don't forget the semicolon)

Shpaget: Yes, they are zero indexed, but index 0 also counts. If you count 0, 1, 2, 3, 4, 5, 6 you'll count 7 items. So declare it:

heatArray[7] ={value1,value2,value3,value4,value5,value6,value7};

(don't forget the semicolon)

I solved my issue. Turns out the last item of an array is not considered a part of an array. And it is irrelevant.

It also means that in an array with ten elements, index nine is the last element. Hence: int myArray[10]={9,3,2,4,3,2,7,8,9,11}; // myArray[9] contains 11 // myArray[10] is invalid and contains random information (other memory address)

Taken from: http://arduino.cc/en/Reference/array

Turns out the last item of an array is not considered a part of an array.

Nonsense.

AWOL: Nonsense.

Maybe I worded it wrong but it says on the official website:

// myArray[10] is invalid and contains random information (other memory address)

So it says myArray[10] has 10 valid items, staring from 0 and ending at 9th item. item 10 is invalid and contains random information. That's what I meant.

A ten element array has ten elements.
It does not have an element with the subscript 10, so it isn’t “your” array.