C++ sorting program

why does this work? shouldn't i<11 since there are 11 values in the array and its from 0-10? when I do i<11 it sometimes gives me an issue depending if I am doing ascending or descending it would give me the address of the last number not the actual value...can anybody explain this to me please?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# include <iostream>
using namespace std; 

int main(){

	int i, temp, ray[] = { 100, 2, 67, 42, 24, 67, 32, 12, 34, 56, 1 };

	for (i = 0; i < 10; i++){
		if (ray[i] < ray[i + 1]){

			temp = ray[i + 1];
			ray[i + 1] = ray[i];
			ray[i] = temp;
		}
		}

		for (i = 0; i < 11; i++){
			cout << ray[i]<<" ";
		}

		int dumbyload;
		cin >> dumbyload;


}
why does this work? shouldn't i<11 since there are 11 values in the array and its from 0-10?
no because you are doing i + 1 ray[i + 1]
ooo so had I put i<11 it should compare to a non existing number?
Topic archived. No new replies allowed.