problem on 2 Dimension array : program breaks in dev C++ but runs fine on visual studio 2008

//runs as i wanted on Debug mode
//runs well on visual studio 2008
//
//doesn't run well when compiled and run on other compilers
#include <iostream>
using namespace std;

int **squareTable;
int squaresNumInHorizontal = 4;


void setSquareTable()
{
squareTable = new int*[4];

squareTable[0] = new int[4]; squareTable[0][0] = 0;squareTable[0][1] = 1;squareTable[0][2] = 2;squareTable[0][3] = 3;squareTable[0][4] = 4;
squareTable[1] = new int[4]; squareTable[1][0] = 10;squareTable[1][1] = 21;squareTable[1][2] = 32;squareTable[1][3] = 43;squareTable[1][4] = 54;
squareTable[2] = new int[4]; squareTable[2][0] = 110;squareTable[2][1] = 221;squareTable[2][2] = 332;squareTable[2][3] = 443;squareTable[2][4] = 554;
squareTable[3] = new int[4]; squareTable[3][0] = 910;squareTable[3][1] = 921;squareTable[3][2] = 932;squareTable[3][3] = 943;squareTable[3][4] = 954;
squareTable[4] = new int[4]; squareTable[4][0] = 810;squareTable[4][1] = 821;squareTable[4][2] = 832;squareTable[4][3] = 843;squareTable[4][4] = 854;

}

void delSquareTable()
{

}
int main()
{

setSquareTable();
int height,width;

cout << "\n";

for(height = 0;height <= 4;height++)
{
for(width = 0;width <= 4;width++)
{
cout << squareTable[height][width] << " ";
}
cout << "\n";
}

system("pause");//This line not reached on Dev C++
return 0;
}
With Dev C++ and VS 2008 you already got 2 IDE's that you probably shouldn't use. But yeah, not reaching there is normal, in fact I'd expect your program to crash as it is within setSquareTable. If you declare an array int a[4];, then you have a 4 element array with subscripts from 0-3, not from 0-4. Also, you might wanna do something about that formatting style of yours, it physically hurts people.


And please put your code between [ code ] [/code] tags.
Thanks
i was confused for it
...and it was eating me for several days;

and why should the code run in debug mode(on every IDEs)
......and runs fine on vs2008(weather debug or not)...?

and i am beginer and was trying to solve magic square problem
3 x 3 magic square would be like this
2 7 6
9 5 1
4 3 8
where
2 + 7 + 6 = 15,
9 + 5 + 1 = 15
....all diagonals and columns sum is equal to 15...

and i wanted to solve it for 5x5, 7 x 7 , 9 x9............




Topic archived. No new replies allowed.