in the above code i am trying to reverse an array by substitute the value of an array from backward direction in the same array but the output is not as expected
Reverse of an array
@abinashkumarray
Your first half part of the array gets overwritten and thus lost i.e. if you run for the first half part , you will notice the data from second half has been copied to the first half but now the original data that was stored in the first half has been lost and now there is no way to retrieve it.
Try something like this.
- Run your loop from i=0 to i=n/2.
- Swap arr[i] and arr[n-i-1].
See if your array gets reversed.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.