Segmentation fault in Matrix - C -


Partition error occurs while running this code. I could not find anything unusual and changing the mat if I change the mat [3] [3] Please tell what is wrong, thank you

  contains #lt; Stdio.h & gt; Zero getdata (int ** mat) {int i, j; {For (j = 0; j & lt; 3; j ++) mat [i] [j] = rand ()% 3; for i (i = 0; i & lt; 3; i ++); }} Zero putdown (mat ** mat) {int i, j; For (i = 0; i    

inside main , mat1 And mat2 will decay an indicator in int [3] , which is not the same as int ** . Therefore, getdata () and putdata () will actually treat the value as a different type, which can be undefined behavior.

  int mat1 [3] [3]; Int (* decayed_mat1) [3] = matte 1; Emphasis (decayed_mat1 == and matte 1 [0]);  

In ACC, the "reference" is passed. In fact it means that the function parameter is declared as an array type, in fact it is on the decay type.

  zero getdata (int mat [3] [3]); Zero (* funcptr) (int (*) [3]) = getdata;  

Changing your function parameter types to int [3] [3] returns the parameter to the type that matches the incoming mails.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -