I am trying do this pratice but some how the 2nd function did return.
P.S>>Since english is my first lang.
can some one explane to me this is right path that i am doing?
here is question:
Write a function that accepts an array of integers and its size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. The function should return a pointer to the new array
Use ONLY pointer parameters instead of arrays in both functions; use pointers (not subscripts) to move through elements of both arrays. Before calling the function, display your original array. When the function call is completed, display the new array.
Here is what i got so far
#include <iostream>
using namespace std;
int *shifted (int * , int);
int main ()
{
int array_size [30];
int size;
int new_number;
cout <<"What is the element of array do you want?" << endl;
cin >> size;
for (int index = 0; index < size; index ++)
{
cin >> array_size[index];
}
new_number = *shifted(array_size , size);
cout <<"The new element is " << new_number << endl;
return 0;
}
int *shifted (int *shifting_arr , int size2)
{
int *new_array=new int[size2+1];
int being = 1;
for (int index =0 ; index <size2 ; index ++)
{
new_array [being] = shifting_arr[index];
being ++;
}
delete [] new_array;
return new_array;
}