I am to make a function that expands an array using pointers and a function. I am rather new to coding in general and I am uncertain as to why I am getting error LNK2019. I am aware that it means there is an unresolved external, but everything that I have changed on it the same error keeps popping up. Here is my code...
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>
#include <vector>
using namespace std;
int * newArray(int[], int);
int main()
{
int arr[] = { 12, 21, 56, 49, 72, 18 };
newArray(arr, 10);
return 0;
}
int * newArray(int arr, int size)
{
int *p;
int arr2;
int *amount = new int[size * 2];
amount = &arr2;
int i;
p = &arr;
for (i = 0; i<size * 2; i++)
{
if (i<size)
{
amount[i] = p[i];
}
else
{
amount[i] = 0;
}
}
arr = arr2;
return amount;
}
Normally I would rather pass a variable by reference to do this but I need to use a pointer for this, if anyone could point me in the right direction it would be much appreciated.