31. Reverse an Array Using Only Pointers

You are given an array of integers and its size n.
Using only pointer arithmetic:

  • Reverse the array elements in-place.
  • Print the reversed array.

❌ Do not use array indexing like arr[I].
✅ Only use pointer movements and dereferencing.

 

Example-1

Input: n = 5, arr = [1 2 3 4 5]
Output: 5 4 3 2 1


Example-2

Input: n = 4, arr = [10 20 30 40]
Output: 40 30 20 10


Example-3

Input: n = 3, arr = [7 8 9]
Output: 9 8 7


 

Loading...

Input

5 1 2 3 4 5

Expected Output

5 4 3 2 1