0

I am trying to reallocate memory for a 2D array element, not the full array But it's not working.

Note: I am new to the C language.

int** resultIndexArr = malloc(sizeof(int**) * 2);
resultIndexArr[0] = realloc(resultIndexArr[0], sizeof(int *) +sizeof(resultIndexArr[0]));
printf("%lu", sizeof(resultIndexArr[0])); // prints 8; but it should be 16;
Dipo Ahmed
  • 327
  • 2
  • 6
  • `resultIndexArr[0]` hasn't yet been assigned a value, so passing it to `realloc` is undefined behaviour. Just use `malloc` again, but see next comment. – Weather Vane Aug 27 '22 at 11:49
  • `sizeof` does not give the size of dynamically allocated memory. Please see the duplicate post for more details. – kaylum Aug 27 '22 at 11:50

0 Answers0