in my c application I have this typedef:
typedef double mat[2][2];
this is my declaration of function:
aaa(mat bbb, mat ccc, mat * ddd)
in my code I want to compute the sum of each member in math and write the result in ddd.
I did it over loops and this is the main line:
*ddd[i][j] = bbb[i][j] + ccc[i][j];
but I’m getting wrong result in ddd.
when I remove the pointer from ddd, I get the right result, but since I want to return it to the user by pointer I want your help.
what is wrong in my code?
You’re writing at the wrong address. It should be:
or simply change the prototype to
since arrays decay to pointers anyway.
dddwill be a copy, but the address it points to will be the same as the original.