1. ## Trouble outputting matrix

I have constructed a program that does the following:
-has one function that adds together two 3x3 matricies and returns a matrix3x3_t pointer.
-main creates two matricies and initializes all their values to 10.
-main stores the result of adding the two matricies together in a matrix called resultMatrix;
-main then attempts to output each value in the resultMatrix

The line that I have put all the '*'s is what is causing my problem
Code:
```#include <iostream>
#include <conio.h>

using namespace std;

typedef struct {
int mat[3][3];
}	matrix3x3_t;

//This prototype SHOULD be set up to return a matrix3x3_t pointer
//	but I am not sure if I set it up correctly
matrix3x3_t * MatrixAdd(matrix3x3_t *matrixA, matrix3x3_t *matrixB, matrix3x3_t *resultMatrix) {
for(int row = 0; row < 3; row++) {
for(int col = 0; col < 3; col++){
resultMatrix->mat[row][col] = matrixA->mat[row][col] + matrixB->mat[row][col];
}
}
return resultMatrix;
}

int main(void) {

matrix3x3_t Matrix1[3][3] = { 10, 10, 10,10, 10, 10,10, 10, 10 };

matrix3x3_t Matrix2[3][3] = { 10, 10, 10,10, 10, 10,10, 10, 10 };

matrix3x3_t resultMatrix[3][3];

int OutPut;	//asign values to this

for(int row = 0; row < 3; row++) {		//while not finished going through the rows
for(int col = 0; col < 3; col++) {		//while not finished going through the columns
OutPut = 0;	//put to zero before doing anything with it, just to be safe I guess
************OutPut = resultMatrix[row][col];***********
if(col == 3)
cout << OutPut << endl;
else
cout << OutPut;
}//col loop
}//row loop

cout << "Please don't hit a key, I'm serious, ACK!" << endl;
getch();
return 0;
}```
I get the following compile time error:
[error]
Compiling...
matricies.cpp
C:\matricies.cpp(41) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'matrix3x3_t' (or there is no acceptable conversion)
Error executing cl.exe.

matricies.exe - 1 error(s), 0 warning(s)
[/error]

Also, I tried aligning the numbers to look like a matrix when I created matrix1 and matrix2, but they just spread a few lines apart and I can't get them to line up the way I want them to.

2. I think this may be your problem
Code:
`resultMatrix[3][3]  = *MatrixAdd(&Matrix1[3][3], &Matrix2[3][3], &resultMatrix[3][3]);`
I suppose you are trying to add matrix1 and matrix2, but the compiler thinks you are trying to set the element in row 3, column 3, to the pointer returned by MatrixAdd. Maybe try this?
Code:
`resultMatrix= *MatrixAdd(&Matrix1, &Matrix2, &resultMatrix);`
Hope that helps

3. by using a typedef to declare your struct the compiler is not able to supply a default assignment operator. therefore the compiler generates an error when you try to assign the return value of the function to another matrix3x3_t. Use a C++ style struct for the declaration and try again.

I assume you realize this could be done much easier without structs or pointers to structs in the first place, and that you are doing this as a self instruction project on the use of pointers to structs? If not, just use the plain 2d arrays. Pointers are powerful, but can be a big waste of (programmer) energy, too.

if you really want 9 instances of type matrix3x3_t to be placed in resultMatrix as a 3 x 3 matrix (that is, resultMatrix is a matrix of matrixes), then the following is appropriate. I'm not sure that's what you want however.

matrix3x3_t resultMatrix[3][3];

in the body of the for loops col will never equal 3.

Code:
```#include <iostream>
#include <conio.h>

using namespace std;

typedef struct {
int mat[3][3];
}   matrix3x3_t;

matrix3x3_t MatrixAdd ( matrix3x3_t *matrixA, matrix3x3_t *matrixB ) {
matrix3x3_t resultMatrix;
for(int row = 0; row < 3; row++) {
for(int col = 0; col < 3; col++){
resultMatrix.mat[row][col] = matrixA->mat[row][col] + matrixB->mat[row][col];
}
}
return resultMatrix;
}

int main(void) {
matrix3x3_t Matrix1 = { { {10, 10, 10},{10, 10, 10},{10, 10, 10} } };
matrix3x3_t Matrix2 = { { {10, 10, 10},{10, 10, 10},{10, 10, 10} } };
matrix3x3_t resultMatrix;

resultMatrix = MatrixAdd ( &Matrix1, &Matrix2 );

for(int row = 0; row < 3; row++) {
for(int col = 0; col < 3; col++) {
cout << resultMatrix.mat[row][col] << " ";
}
cout << endl;
}

cout << "Please don't hit a key, I'm serious, ACK!" << endl;
getch();
return 0;
}```