Reverse an array without using subtract sign â €˜ | C ++ program to reverse an array without using " - " sign ; Function to reverse array ; Trick to assign - 1 to a variable ; Reverse array in simple manner ; Swap ith index value with ( n - i - 1 ) th index value ; Drivers code ; print the reversed array
#include <bits/stdc++.h> NEW_LINE using namespace std ; void reverseArray ( int arr [ ] , int n ) { int x = ( INT_MIN / INT_MAX ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) swap ( arr [ i ] , arr [ n + ( x * i ) + x ] ) ; } int main ( ) { int arr [ ] = { 5 , 3 , 7 , 2 , 1 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; reverseArray ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; return 0 ; }