I am working on a program and I successfully isolated the non-working part, but I can't figure out why this does not work. The realloc inside the function shold reallocate the array elements but sometimes the addresses are the same and sometimes they are just 0, which causes errors inside the code and crashes
int main() {
char *string = (char*) malloc(sizeof(char));
resizeString(&string);
free(string)
return 0;
}
void resizeString(char* *string) {
int q;
*string = realloc(*string, 5 * sizeof(char));
for (q = 0; q < 5; q++) {
printf("0x%p ", &*string[q]);
}
printf("\n");
}