Passing 2D arrays

After trying to run some code, the code seems to compile, but during run time, i get the following error message:

Unhandled exception at 0x777e15de in Hot Plate.exe: 0xC0000005: Access violation.

I was trying to fill a 20x20 array with 100 on the top and bottom rows(except the corners) and the rest as 0.
Here is my code:

#include <iostream>
#include <string>
#include <array>

using namespace std;

const int SIZE = 20;

void initial_temp(double temp[][SIZE])
{
for (int i = 1; i<SIZE; i++)
{
const double ELEMENT = 100;
temp[0][i]=ELEMENT;
temp[SIZE][i]=ELEMENT;
for (int row = 1; row<SIZE; row++)
{
temp[i][row]=0;
}
}
for (int i =0; 1<=SIZE; i++)
{
temp[i][0]=0;
temp[i][SIZE]=0;
}
return;
}


int main()
{
double temp[SIZE][SIZE];
initial_temp (temp);
return 0;
}

The error message gives the option to break, and shows the breakpoint at the line where i try to call initial_temp() in main().
The assignment is due tomorrow and I have a long way to go, any help would be much appreciated.
Several errors:
1<=SIZE should be i<SIZE Note 1 and i

temp[SIZE][i] and temp[i][SIZE]
should be temp[SIZE-1][i] and temp[i][SIZE-1]

Thanks, could you elaborate on why it gave me such an odd error code?
All these errors result in data outside the boundaries of the array being accessed.
The subscript needs to go from 0 to 19.

If you try to update memory which you do not own, an access violation is the result.

The 1<SIZE error was the biggest, as both 1 and SIZE are constant, thus the loop never terminates and the program would go on writing to memory throughout the whole machine, if it was allowed.

I think "0xC0000005" is a standard Microsoft error code, Google returns lots of hits for it.

Last edited on
Thanks again
Topic archived. No new replies allowed.