**Preface**

Of course in c++ there are much more elegant solutions possible. This in case you implement a class Matrix (and Vector). But that was not your question.

**Implementation trial according to your question**

Here an implementation

**completely untested**, but I think because of some meaningfull namings more easy to understand and hopefully correct. Another thing: I'm assuming the matrices hold double values. Change the type according to your needs.

C++

void MatrixMul(double A[], int ARows, int ACols, double B[], int BRows, int BCols, double C[]) { // Assertion test. For matrix multiplication the left hand column count needs to match the right hand row count. if (ACols != BRows) { throw(*new Exception("Dimension Error")); } int CRows= ARows; // Result Rows int CCols= BCols; // Result Cols for(int CRowIx= 0; CRowIx < CRows; CRowIx++) { for(int CColIx= 0; CColIx < CCols; CColIx++) { double Sum= 0.0; // Assuming the matrices hold double values. for(int k= 0; k < ACols; k++) { // sum+= B[k][CColIx] * A[CRowIx][k]; Sum+= B[k * BCols + CColIx] * A[CRowIx * ACols + k]; } // C[CRowIx][CColIx]= sum; C[CRowIx * CCols + CColIx]= Sum; } } }

**Notes**

Of course more index range checking are necessary to make it 'access violation" safe.

I hope it helps.