The function will not behave as expected because of a bug within findMax's parameters. The argument: int* pToMax, creates a local copy of the pointer passed to findMax. Because findMax is of return type void, the function returns nothing. Any changes made to pToMax are also deleted when the function returns. To fix this, I would change the argument to be passed by reference instead of value like so:
void findMax(int arr, int n, int* &pToMax)
The main function has a problem in that a pointer is declared but not initialized to any memory address. As a result, a compilation error arises when computeCube is called with ptr as an argument. To fix this, I declared an int var and initialized it to some arbitrary value. I then assigned ptr to the address of var.
int var = 0;
int* ptr = &var;
cout << "Five cubed is " << *ptr << endl;
The implementation of strequal causes it to run into problems when comparing str1 and str2. Instead of comparing the characters at the memory addresses that str1 and str2 currently point to, the while condition only compares the memory addresses. The if statement and return condition also run into the same problem. To fix this, I dereferenced the pointers with a * character whenever str1 and str2 were compared.
Get Free Quote!
317 Experts Online