I want to memset a 2D array to 0. Here\'s my code.. But it always giving me seg fault;
bool **visited=new bool*[m];
for(int i=0;i
Your array is not contiguous since it is not actually a multi-dimensional array. It's an array of arrays, sometimes known as a jagged array.
So, your rows can, and will, be disjoint. Hence you'll need to call memset on each row.
bool **visited=new bool*[m];
for(int i=0;i<m;++i)
{
visited[i] = new bool[m];
memset(visited[i], 0, sizeof(visited[i][0]) * m);
}
Although, I can't refrain from pointing out that you should probably be using C++ features rather than writing what appears to be C with the use of the new operator.