Home > Net >  a value of type "void" cannot be used to initialize an entity of type "double**"
a value of type "void" cannot be used to initialize an entity of type "double**"

Time:09-17

I use C language and I have problem with malloc


  double** matrix = malloc(matrixSize * sizeof(double*));

  for (size_t i = 0; i < matrixSize; i  ) {
    matrix[i] = malloc(matrixSize * sizeof(double));
  }

  return matrix;
}`

CodePudding user response:

malloc returns a void-pointer

void *malloc(size_t size);

so you will have to typecast this to double**

double** matrix = (double**)malloc(matrixSize * sizeof(double*));
  • Related