I'm learning C at the moment and tried to write this function
int *create_matrix(int n) {
int *matrix = malloc(n*n*sizeof(int));
srand(time(NULL));
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
matrix[i][j] = rand()%10;
}
}
return matrix;
}
why does this fail to compile? its complaining about matrix[i][j]
is not an pointer/array. but I've just declared it as an pointer six lines above...