Print out orgain array

I need help with cout orgain array.

At cout <<"Here is array that you just enter " << index << endl; i got lldb...

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
{
    int array[SIZE];
    int *Shifted;
    int size, i;
    
    cout << "Enter size of array: " << endl;
    cin >> size;
    cout << "Enter elements: ";
    for(i=0;i<size;i++)
    {
         cin >> array[i];
    }
    for (int index = 0; index < i; index++)
    {
        cout <<"Here is array that you just enter " << index << endl;

    }
    
    Shifted=Shifted_array(array,size);
    
    cout << "The elements after shifting the array: " << endl;
   
    for(i=0;i<size+1;i++)
    {
        cout << *(Shifted+i) << endl;
    }
}
The method you are using can't really be viable.

See, the problem is, that array size has to be determined at compile time. If you want to create an array which size will be decided on run time(e.g. user will tell you how big array should be), then you need to use dynamic allocation(using pointers and new keyword). I suggest you to read about arrays, and then about creating dynamic arrays.

Also, the for loop at line 13 will not work as intended. It will simply print out numbers from 0 to i-1. This is not what you wanted to do. Try to fix it as an exercise :)
I have everything and code is working perfectly. I just need to know how count the orgain before new array
> how count the orgain
sorry, I don't understand.


If you want to output the array, then you could simply
1
2
for(int K=0; K<size; ++K)
   cout << array[K] << ' ';
(also, if you've got good reasons to believe that `i' would not be equal to `size' after line 12, then perhaps you should consider to change their names)
Your program is working perfectly, because you know how it is supposed to be used. Try to say that size of array will be SIZE + 1(so, if you set SIZE previously to 11, you will input 12. If it was 3, then you input 4, etc.). And look at your program failing, because you try to access memory address you're not supposed to access.
Topic archived. No new replies allowed.