Hi guys, I'm totally in shock why it's not working although I'm really good on pointers !
I want to pass array 2D (MATRIX) to the called function and change on the same matrix some modifications on it, and I want to keep the changes on the matrixs itself even though I passing it and changing it the called function .
my code:
I've ran this code, the compiler not showing me any errors but it's not printing the matrix after manipulation, it's printing the values of the matrix as what it was before doing function "change" , in other words the manipulation on the matrix didn't save. any clue? what's wondering my after doing the function change in the main function, the values of "matrix" after returning from the change function doesn't change at all .. like the function change didn't do anything ! weird!!Code:void change(int **mat) { for (int i=0;i<2,i++) for(int j=0;j<2;j++) mat[i][j]=1; } int main() { int matrix={ {0 0}, {0 0} }; change(matrix); for (int i=0;i<2,i++) for(int j=0;j<2;j++) printf("%d", matrix[i][j]); return 0; }
I used pointer **mat to keep the change on the passed matrix however didn't save !
any help please how can I solve the problem? thanks for your cooperation.