Multidimensional Array issue

I have the following code, and every time I run it it outputs about a million numbers of random value and I get the following error:

Unhandled exception at 0x5100261b (msvcr100d.dll) in Random_apps.exe: 0xC0000005: Access violation reading location 0x8779a505.

My code seems good, I don't understand the error. Please help me out.

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
31
32
33
34
35
36
#include <iostream>

using namespace std;

int main()
{
	int Matrix_1[2][3] =
	{
		{5, 8, 11},
		{11, 3, 2}
	};

	int Matrix_2[2][3] =
	{
		{20, 13, 312},
		{10, 14, 210}
	};

	int Matrix_12Sum[2][3] = {};

	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < 3; ++i)
		{
			Matrix_12Sum[i][j] = Matrix_1[i][j] + Matrix_2[i][j];

			cout << Matrix_12Sum[i][j] << " ";
		}

		cout << endl;
	}




}


1
2
3
4
5
6
7
8
9
10
11
for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < 3; ++i)
		{
			Matrix_12Sum[i][j] = Matrix_1[i][j] + Matrix_2[i][j];

			cout << Matrix_12Sum[i][j] << " ";
		}

		cout << endl;
	}


Look at your second loop, you have ++i instead of ++j! lol
lol, woops. Code is fixed now, thanks
Just as a note, when you get 'Access violation' you are trying to read/write to memory that's not yours.

In many cases, this is when a loop is incorrect, so that would be the first thing to check for.

Also, don't forget to mark the thread as 'solved' at the top of this page (:
Sweet, thanks. ;-)
Topic archived. No new replies allowed.