#include<iostream>
using namespace std;
int main()
{
int a[]={1,2,3,4,5}; // Using Pointer and Array Relationship
for (int i = 4; i>=0; i--)
cout<<*(a+i);
return 0;
}
// C++ program to reverse Array
// using reverse() in STL
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
// Get the array
int arr[] = { 1, 45, 54, 71, 76, 12 };
// Compute the sizes
int n = sizeof(arr) / sizeof(arr[0]);
// Print the array
cout << "Array: ";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
// Reverse the array
reverse(arr, arr + n);
// Print the reversed array
cout << "
Reversed Array: ";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}
//Reverse an array using C++ STL
#include <algorithm> //Header file for reverse method
int arr[] = { 1, 2, 3, 4, 5 };
int n = sizeof(arr) / sizeof(arr[0]); //Size of array
reverse(arr, arr + n);
//Now array looks like = { 5, 4, 3, 2, 1 }
//The time complexity is O(n)
//https://www.linkedin.com/in/kalyan-santra-44589a126/
Code Example |
---|
Cpp :: concatenate string program in c++ |
Cpp :: play audio c++ |
Cpp :: round double to 2 decimal places c++ |
Cpp :: log base 10 c++ |
Cpp :: c++ isalphanum |
Cpp :: how to send email in c++ program |
Cpp :: how to create a vector in c++ |
Cpp :: c++ standard library source |
Cpp :: declaring 2d dynamic array c++ |
Cpp :: hello world program in c++ |
Cpp :: delete dynamic array c++ |
Cpp :: indexing strings in c++ |
Cpp :: check if set contains element c++ |
Cpp :: powershell get uptime remote computer |
Cpp :: char size length c++ |
Cpp :: c++ function default argument |
Cpp :: remove specific element from vector c++ |
Cpp :: concatenate two vectors c++ |
Cpp :: reverse function in cpp array |
Cpp :: c++ vector of class objects |
Cpp :: C++ Limit of Integer |
Cpp :: c++ do every 1 minutes |
Cpp :: Converting to string c++ |
Cpp :: c plus plus |
Cpp :: demonstrate constructor |
Cpp :: min element in vector c++ |
Cpp :: find substring in string c++ |
Cpp :: toupper c++ |
Cpp :: c++ shell |
Cpp :: take a function argument |