I am trying to get back multiplied matrix array from pointer function to main.
I am getting error as timeout: the monitored command dumped core. how to get any array return from function to main?
Here is the code:
/* multiplication of matrix in function and printing it in main */
#include <stdio.h>
int pointer(int *, int *); /* function to multiply two matrices */
int main() {
int i, j, *a;
int ar2[3][3];
int ar[3][3] = {
1, 1, 3,
2, 1, 8,
3, 8, 1
};
int ar1[3][3] = {
1, 1, 3,
2, 1, 8,
3, 8, 1
};
a = pointer(ar, ar1);
printf("asas");
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
printf("%d ", a[i][j]);
}
printf("\n");
}
}
int pointer(int *l, int *k) {
int i, j, a, m = 0, *n;
int ar[3][3];
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
for (a = 0; a <= 2; a++) {
m += *(l + a * 3 + j) * (*(k + a + i * 3));
}
ar[i][j] = m;
m = 0;
}
}
n = ar;
return (n);
}