i want to write a function to which i need to pass two matrices and get the sum and product of them as output. but how can i return more than one matrix from a function? (i want to pass and return using pointers)

Edited 5 Years Ago by vineeshvs: n/a

int matrix_ops(matrix * m1, matrix * m2, matrix * sum, matrix * pdt)

Where sum and pdt are empty matrices to be filled in within the function.

1.It means i dont have to return the matrices but just define them in the main program and change the values of the matrices inside the function. ritht?
2. Will it be better if I declare sum and product as global variables (before main()) and find them inside function without returning them?

The implementation would look something like

int main () {
   matrix m1, m2, sum, pdt;
   int status = matrix_ops (&m1, &m2, &sum, &pdt);
   if (status != 0) {
      /* error condition, handle it */
   } else {
      /* at this point sum and pdt are filled in as matrix_ops allows */
   }
   // ...
}

Hey,but why do you want to pass arrays by reference,as arrays are passed by reference by default.
so make any changes that you want to make in the called function,you will get the changed array inside your calling function.

This question has already been answered. Start a new discussion instead.