void reverseString(char* const src, char* reversed)
{
reversed = new char[strlen(src)+1];
for(unsigned int i = 0; i < strlen(src) - 1; i++)
{
unsigned int resIndex = strlen(src) - i - 1;
reversed[resIndex] = src;
}
reversed[strlen(src)] = '\0';
}
int main(void)
{
char* original = "Hello World!";
char* reversed = NULL;
reverseString(original, reversed); //reversed should be assigned in here
cout << original << endl << reversed; //however reversed is still NULL here?!
cin.get();
return 0;
}
The code should assign reversed to a value inside reverseString(). And, at the end of reverseString() before the program branches back to main() the pointer is assigned to the correct value. However, upon reaching cout, the reversed pointer is NULL again. Can someone explain what is going on here?