Can someone please review this simple code

2 dimensional arrays have been killing me so far.
One dimensional seems pretty straight forward,but once i start thinking 2 dimensional i get stuck .

concerns:
2 dimensional arrays are not really stored 'grid' like in memory right?the computer sees it linearly?



Why does the code below give me a segmentation fault?memory access violation.

I tried it 3 times and the fourth time i was able to display all the numbers from 1-9 , i haven't gotten a seg fault since.

I have the same type of code on code::blocks.
this is done on visual studio 2010.

any links,tuts,where i can learn more about how to handle multidimensional arrays ?
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
#include "stdafx.h"
#include <iostream>

using namespace std;

#define ROW 3
#define COL 3


int main()
{
	int array2D [ROW][COL]= {{1,2,3},{4,5,6},{7,8,9}};
	
    for (int i = 0 ;i<ROW;i++)
	{
	  for (int k = 0;k<COL;k++)
		 {
		 cout<<array2D[i][k]<<endl;
		 }
	}	 
	

	cin.get();
	return 0;
}


thanks for the help guys.

Last edited on
@anon2343

You need to put a '#' before include <iostream> and change int main(int argc, _TCHAR* argv[]) to just int main()
Someone has the same problem as you, except more extreme here
http://www.tnbforum.com/viewtopic.php?f=118&t=20850&p=125616#p125616
. There is a chance its your system that's causing you a problem. but it could also be as simple as the post above ^^
@whitenite1 i am sorry...i did not copy and pasted the code correctly but it does include that.

will edit it anyway for clarity.


@need4sleep


Sorry but i don't use kimodo firewall.
but i haven't had the same problem again right now,i would link to a snapshot of it but i can't recreate it again.

thanks for the help guys
Topic archived. No new replies allowed.