Segmentation Error 11

My code uses a function for the multiplication of two matrices, then a pointer function is used to call the matrix multiplication function. However, I get a segmentation error (11) when attempting output the solution of the pointer function. Any ideas?

Thanks!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include void matrixMultiplication (const double A[3][3], const double B[3][3], double output[3][3]) { int i, j, k; for (i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { output[i][j]+=A[i][k]*B[k][j]; } } } } double (*MM (const double (*left)[3], const double (*right)[3]))[3] { double output[3][3]; matrixMultiplication(left, right, output); } int main () { using namespace std; double A[3][3]={{1,1,1},{1,1,1},{1,1,1}}; double B[3][3]={{1,1,1},{1,1,1},{1,1,1}}; cout<<"The function MM returns..."<
Why are you `delete`'ing `print`, if it was never `new`'d. Since your matrixMultiplication function returns it's result by argument, use it that way, and skip the middle man (that's what MM stands for?):
In place of line 36:
 `` `` ``matrixMultiplication(A, B, print);``

For it to work, print should be declared as an empty array, or you will get random numbers. So, to sum up, in place of line 36 use 2 lines:
 ``12`` ``````double print[3][3] = {0}; matrixMultiplication(A, B, print);``````
Last edited on
Sorry, I'm a bit of a rookie when it comes to C++

So I'm trying to do an exercise in code reuse by introducing a pointer function 'MM' that calls the function matrixMultiplication. But I'm having problems trying to output the matrix formed by this pointer function
Topic archived. No new replies allowed.