Initializing a 2d dynamic array with all entries 0

is it possible to create a dynamic array with all entries in it equal to 0?
1
2
3
4
5
 int** adjMatrix;
 adjMatrix= new int*[numOfVertices];
for(int i=0; i<numOfVertices; i++){
    adjMatrix[i]=new int[numOfVertices];
}

Last edited on
You can tell new[] to initialize the values to zero by putting a pair of parentheses after the type name:
adjMatrix[i] = new int[numOfVertices]();

but in general, consider using a matrix library (or even a graph library since that's what you're after - there is a good one in boost)
Topic archived. No new replies allowed.