I'm using malloc
to allocate memory for a matrix, but afterwards any access I do to the matrix to set an element for example gets me a segmentation fault.
This is what I'm doing right now:
int **matrix = malloc(rows_number * columns_number * sizeof(int));
if (matrix) matrix[0][0] = 1;
Why can't I access the matrix after it was created? The malloc
call is successful so I have enough contiguous memory for the whole matrix.