exam study question

Fill in the code below to reverse the order of array1’s contents and save it into array2 (Assume array1 contains valid data, and you may ONLY declare ONE extra variable)

1
2
  for (int i = 0; i SIZE; i++) {
array2[ ] = array1[ ];

I tried
1
2
3
for (int p=0; p<woo; p++){
         rev[p]=extra[(woo-p)];
     }


When I input 1,2,3,4,5 I get out 0,5,4,3,2,

Just studying for an exam I have on weds. Thanks
closed account (j3Rz8vqX)
You almost got it, but you're incorrect with a bit of the logic.

Assuming p=0, woo=5.

array1[p] = array2[woo-p];

You would get 5-0.

Is array @ index 5 available?

An array of 5 would have: INDEX=[0][1][2][3][4] == valid -----------------([5] == Invalid)

Repeating, woo-p=5!

Think about it, you may already know the answer.
Last edited on
Thanks!
This still doesn't work out for me, thanks anyways!
Topic archived. No new replies allowed.