I have been working with c++ and for some reason it keeps giving me this error message each time it encounters an array being accessed in a loop e.g:
int i2 = 0;
for(int n=0; n<sizeof(mapy); n++)
{
xybar[i2] = mapx[n] * mapy[n];//
xbar_squared[i2] = mapx[n] * mapx[n];//
i2++;
}
The reason for the i2 as I realise its not needed is that because when I examine the values I realise that the iterator n has been replaced with the value say 2006 instead of the location within the array causing it to fail on the next call as it is out of bounds since my arrays only contain 500 pieces of data. I thought i2 might solve this problem however it did not.
I hereby assume that your arrays are not pointers, e.g. they are
sometype mapy[size]and notsometype *mapy. In this case thesizeofoperator returns the size of the wholemapyarray in bytes, not the number of elements. If the array is of any type which is larger than 1 byte (e.g.int,float,double, etc.) then the code would access past the end of the array and hence the access violation exception. You may usesizeof(mapy)/sizeof(mapy[0])instead to get the number of array elements.