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.