void allocateMemory(char* pString, int length) {
pString = (char*)malloc(length);
}
void test() {
char* pString = NULL;
allocateMemory(pString, 20);
strcpy(pString, "Hello world.");
}
Why does this program crash? I have allocated memory using malloc. When the function returns I would expect that pString points to a memory on the heap? Isn't this what is happening? Seems like pString still points to null?
Can't we change the address to what a pointer points to?