I'm trying to add values inside a matrix. For the first row everyting goes well. However, when I'm trying to access the second row (if there's one), I get an invalid write.
Here is the the different version I wrote :
- mat[i][j]
- *(*(mat + i) + j)
- mat[i * N + j]
int** matrice(int N, int M){
int **mat = (int **)malloc(N * sizeof(int*));
for(int i = 0; i < N; i++) mat[i] = (int *)malloc(M * sizeof(int));
for (int i = 0; i < N; i++){
for (int j = 0; i < M; j++){
//mat[i][j] = i+j;
}
}
return mat;
}