int** z= new int *[5];
for (int j = 0; j < 8; j ++)
{
z[j] = new int[5];
}
for (int n=0; n<8; ++n)
{
for(int m=0;m<5;++m)
{
int x=n%4;
int y=x*wB;
int p=(*(B+(y+m)));
z[n][m]=p;
}
}
return z;
throws a Bad_Acess_error at n=6, but
int** z= new int *[5];
for (int j = 0; j < 8; j ++)
{
z[j] = new int[5];
}
for (int n=0; n<8; ++n)
{
for(int m=0;m<5;++m)
{
int x=n%4;
int y=x*5;
int p=(*(B+(y+m)));
z[6][m]=p;
}
return z;
}
throws no error. Why? This is really weird and I can't seem to understand why this is happening. I am just typing in more text so it allows me to publish this question.
Edit: replaced variables with numbers. The numbers are just limits of the array in question. I know the second code works because the output is exactly what I expect it to be.
wB?wb? It also looks like you have your conditions backwards.wbshoul be the limit of the outer for loop not the inner loop.j<8andn<8? Sometimes you usewBsometimes the magic number8. Anyway, as soon as you access an array outside its definition range, the C++ runtime is free to do anything as far as the C++ standard is concerned, including both reporting or not reporting an error. It is very likely that your second program just looks to be fine, but actually is not.