doing some assignment, here's a function to count negative numbers in a dynamically allocated 2D array:
void numberOfNegs(int** arrayPointer, int n) {
int counter{ 0 };
for (int i{ 0 }; i < n; i++){
for (int j{ 0 }; j < n; j++){
if (arrayPointer[i][j] < 0) {
counter++;
}
}
}
Seems legit to me, but the debugger throws this error:
Unhandled exception at 0x00C25D9A in *.exe: 0xC0000005: Access violation reading location 0xCDCDCDCD.
Please, help
Here's more code on how I casted it
std::cin >> x;
int** theMatrix = new int*[x];
for (int i{ 0 }; i < x; i++){
theMatrix[x] = new int[x];
}
std::cout << "Please enter a matrix " << x << std::endl;
for (int i{ 0 }; i < x; i++) {
for (int j{ 0 }; j < x; j++) {
std::cin >> theMatrix[x][x];
}
}
numberOfNegs(theMatrix, x)