I'm trying to dive a little bit into C programming. So I'm trying to create a 2-d array using double pointers and initializing it with random values. However during the access phase it throws a segmentation fault
Below is a striped down snippet of my code:
int main(void){
// Memory allocation for arrays
int size = 3;
double **matrix = (double **)malloc(sizeof(double *)*size*size);
int i, k;
for(i=0; i<size; i++){
for(k=0; k<size; k++){
matrix[i][k] = ((double)rand())/1314.7;
}
}
return 0;
}
Could you please point me what am I doing wrong?