Hi everyone! I'm new to pointers and they are stumping me. I have this program where I have to write a function to resize an array and copy the contents of the old array into a new array with the new size using this prototype:
double* resize(double* array, int old_size, int new_size)
I increased the size just fine, but I cannot figure out how to return the new array. I keep getting a print of the address of the pointer. =S
Here's my code:
#include <iostream>
using namespace std;
double* resize(double* array, int old_size, int new_size)
{
int size = old_size;
resize(array, 5, 15)
That returns a pointer to a double. So you've output a pointer. A pointer is an address. You're not getting the address of the pointer; you're getting the address of the array it's pointing to.
If you want to output what a pointer points to, use the dereference operator. cout << *(resize(array, 5, 15)) << endl;
The << operator is overloaded for a char* to handle it differently, but for everything else, it's up to you.
When i used cout<< *(resize(array,5,15))<<endl; it printed out the first number in the array which is great, but how would i print out the entire array??