Quick question about pointers.

I have
int** matrix
and I want to set each element to zero, how would I go about doing that, I have tried
1
2
3
4
5
6
7
8
9
*matrix = new int[5];//it does not like this
for(i = 0; i < 5; i++)
{
  for(j = 0; j < 5; j++)
  {
  matrix[i] = new int[5];
  matrix[i][j] = 0;
  }
}

So what am I dong wrong?
move "matrix[i] = new int [5]" above "for (j = 0...)"
Okay that makes sense but it still crashes at
*matrix = new int[5];
It says "Access violation writing location 0xcccccccc"
There you're dereferencing matrix which you haven't initialized yet. At the top, you want:

matrix = new int*[5];
Ah I see, thanks.
Topic archived. No new replies allowed.