This code compiles and runs, but the next code . . .
int main ()
{
int** array;
int x, y;
for (int i = 0; i < 10; i++)
{
array[i] = new int[10];
}
for (int i = 0; i < 10; i++)
{
delete array[i];
}
return 0;
}
The follow code crashes, why?
int main ()
{
int x, y;
int** array;
for (int i = 0; i < 10; i++)
{
array[i] = new int[10];
}
for (int i = 0; i < 10; i++)
{
delete array[i];
}
return 0;
}
The only difference is that I swapped lines 3 and 4. Why is it that the first code will compile and execute and the second code crashes? (the crash point is in the loop)
2007-07-27
10:36:12
·
4 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design