array reverse in c++ code example
Example 1: reverse an array in cpp
#include<iostream>
using namespace std;
int main()
{
int n=3;
int arr[]={1,2,3,4};
while (n>=0)
{
cout<<arr[n];
n--;
}
return 0;
}
Example 2: c++ reverse array
int arr[5] = {1, 2, 3, 4, 5};
for(int i = 0; i < size(arr); i++) {
int temp = arr[i];
arr[i] = arr[size(arr) - 1 - i];
arr[size(arr) - 1 - i] = temp;
}
Example 3: reverse c++
reverse(str.begin(),str.end());
Example 4: reverse() in c++
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
int main()
{
vector<int>a = {11,22,33,44,99,55};
reverse(a.begin(), a.end());
auto it = a.begin();
for(it= a.begin(); it!=a.end(); it++){
cout << *it << ' ';
}
}