Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know exactly what did you want to accomplish but I think it was something like this:</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstring&gt; // Needed to compile on most compilers(memcpy), dunno in yours using namespace std; // Function prototypes int *reverse(int *, int); int *expand(int *, int); int *shift(int *, int); void display(int[], int); void display2(int[], int); int main() { int const SIZE = 5; int myArray [SIZE] = {1, 2, 3, 4, 5}; int myArray2 [SIZE] = {1, 2, 3, 4, 5}; int myArray3 [SIZE] = {1, 2, 3, 4, 5}; int *arraPtr; int *arraPtr2; arraPtr = reverse(myArray, SIZE); display(arraPtr, SIZE); arraPtr2 = expand(myArray2, SIZE); display2(arraPtr2, SIZE * 2); delete [] arraPtr; delete [] arraPtr2; return 0; } int *reverse(int *arr, int size) { int *copyArray; int posChange; if( size &lt; 0) return NULL; copyArray = new int[size]; for (int index = 0; index &lt;= --size; index++) { posChange = arr[index]; copyArray[index] = arr[size]; copyArray[size] = posChange; } return copyArray; } int *expand(int *arr, int size) { int *newArray; newArray = new int[size * 2]; memcpy( newArray, arr, size * sizeof(int)); for (int index = size; index &lt; (size*2); index++) newArray[index] = 0; return newArray; } int *shift(int *arr, int size) { int *newArray; newArray = new int [size + 1]; memcpy( newArray, arr, size * sizeof(int)); return newArray; } void display(int arr[], int size) { for (int index = 0; index &lt; size; index++) { cout &lt;&lt; endl &lt;&lt; arr[index] &lt;&lt; " "; } } void display2(int arr[], int size) { for (int index = 0; index &lt; size; index++) { cout &lt;&lt; arr[index] &lt;&lt; " "; } } </code></pre> <p>As a side note, if you have problems with this kind of stuff you should take a look at any good C resource that talks about pointers and pointer arithmetics, it will come in handy when you have to do low level C++ code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload