Shifting the array

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.

P.S. My english is my 7 lang.

I didnt show anything

here is what i got so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

using namespace std;
int *shifted (int * , int);

const int SIZE = 10;

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];
    for (int index =0 ; index <size2 ; index ++)
    {
        new_array [index] = shifting_arr[index];
    }
    return new_array;
    
}
You're still using array offsets in shifted. Also, you're not setting the first element to zero.
Topic archived. No new replies allowed.