one dimention Array

when i debug this code it shows me this error message, Stack around the variable 'A' is corrupte. what does that even mean?? Just to be clear i want the program to swap the upper half with the lower half. like this A[0]=A[5].
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
27
28
29
  int main()
{
	int A[10];
	int i,s;
	float av;

	for (i = 0; i <= 9; i++)
	{
		cout << "A[" << i << "]=";
		cin >> A[i];
	}
	for (i = 0; i <= 9; i++)
	{
		s = A[i];
		A[i] = A[i + 5];
	 A[i + 5] = s;
	}

	
	for (i = 0; i <= 9; i++)
	{
		cout << "A[ " << i << " ]=";
		cout << A[i];
	}


	return 0;

}
Last edited on
when i is in the range 5 to 9, this statement at line 16 is corrupting some memory outside the array:
 
    A[i + 5] = s;

Thanks alot... it gave me an insight of what was wrong..
now this code works just fine.
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
27
28
29
30
int main()
{
	
	
		int A[10];
		int i, s;

		for (i = 0; i <= 9; i++)
		{
			cout << "A[" << i << "]=";
			cin >> A[i];
		}
		for (i = 0; i <= 4; i++)
		{
			s = A[i];
			A[i] = A[i + 5];
			A[i + 5] = s;
		}


		for (i = 0; i <= 9; i++)
		{
			cout << "A[ " << i << " ]=";
			cout << A[i] << endl;
		}


		return 0;

	}
Topic archived. No new replies allowed.