Unknown Error

I try some codes consisting of arrays, but when I run it, I got errors, and this is what it says. "Unhandled exception at 0x508A6D26 (msvcp110d.dll) in TestTimer.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC."

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

int main()
{
	int answer;
	string question[5] = {"What does the fox say?", "Sino ka?", "1+1 = ?", "What is asked?", "What is given"};
	string questionNumber[5] = {"Question no. 1", "Question no. 2", "Question no. 3", "Question no. 4", "Question no. 5"};

	for (int x = 0;x <= 5;x++)
	{
		cout << questionNumber[x] << "   " << question[x];
		cout << endl << endl;
	}

	getch();
	return 0;
}
When you create an array with the size of, in this case, 5. They are placed in indexes between 0-4.

In the for loop. You say <=5. Thats indexes 0-5. What you want is 0-4. Which is between 0 and < 5.

for (int x = 0;x < 5;x++)
Thanks for reply. I thought that array starts from 1, but its starts from 0. Thanks
Topic archived. No new replies allowed.