Acces violation error

Hello guys. I am trying to make a program for my school project and I have no idea why i keep getting error about access violation. I assume I do somthing wrong with pointers or i pass them the wrong way, but I can't fix it by myself so im asking for help.

This is how i create my tab table and call function generate
1
2
3
4
5
  int ** tab = new int * [n / 2];
        for (int m = 0; m < n / 2; m++) {
          tab[m] = new int[y[0]];
        }
   generate(n, k, tab, x);


This is how i declare function generate
 
 void generate(int n, int k, int ** tab, int x)


And in that part when i try to clear the memory i get access violation error
1
2
3
  for (int m = 0; m<n/2; m++)
        delete [] tab[m];
    delete [] tab;  


Thanks for any help.
somewhere not shown you have gone out of bounds.
eg
int x[100];
x[100] = 3; //access violation: only 0-99 are legal
Consider using a C++ container, like a std::vector, for dealing with runtime sized arrays. Manual memory management is fraught with pitfalls if you aren't careful as you are finding out.

I know, a class assignment.

An actual 2D std::vector isn't all that difficult to set up, and then filling the various elements is looping through the 2D already present in memory.
Topic archived. No new replies allowed.