Reverse an Array in C++17 Mar 2025 | 6 min read This section will discuss the different ways to reverse an array in the C++ programming language. The reverse of an array means to change the order of the given array's elements. This technique reverses the last element of the array into the first one, and the first element becomes the last. However, the process continues until all characters or elements of the array are completely reversed. For example, the array contains elements like 'H', 'E', 'L', 'L', 'O', and when we reverse all the elements of an array, it returns the inverted array as 'O', 'L', 'L', 'E', 'H'. So, this way, all the characters in the array are reversed. ![]() Different ways to reverse an arrayFollowing are the various ways to get the reverse array in the C++ programming language.
Program to reverse an array using the for loopLet's create a program to reverse the elements of the array using for loop in C++. Program1.cpp Output Please, enter the total no. you want to enter: 6 Enter the element 1: 78 Enter the element 2: 12 Enter the element 3: 54 Enter the element 4: 24 Enter the element 5: 7 Enter the element 6: 90 Reverse all elements of the array: 90 7 24 54 12 78 Program to reverse an array using the reverse() functionLet's consider an example to print the reverse of an array using the reverse () function in C++. Program2.cpp Output 2 5 90 21 78 34 Program to reverse an array using the user-defined functionLet's consider an example to display the reverse of array elements using the user-defined in C++. Program3.cpp Output Number of elements to be entered: 7 Enter the array elements: 45 32 89 21 78 34 65 Elements are: 45 32 89 21 78 34 65 The reverse of the given array is: 65 34 78 21 89 32 45 Program to reverse an array using the pointerLet's consider an example to demonstrate the reversing of the array elements using the pointers in C++. Program4.cpp Output No. of array elements to be entered:
6
Enter the elements: 45
32
89
63
4
6
Entered elements of the array are:
45 32 89 63 4 6
The reversed array elements are:
6
4
63
89
32
45
Reverse an array using the Recursion functionLet's create a program to reverse the array elements using the recursion function in C++. Program5.cpp Output Original elements of the arrays 20 34 5 8 1 78 Reverse elements of the array are: 78 1 8 5 34 20 Next TopicC++ date and time |
Finding a Peak Element in an Array in C++
Elements that are larger than the elements to them are called peak elements in an array. They can be very important in many different applications, such as dataset identification or algorithm optimization. In this article, we will learn how to find a peak element in...
4 min read
C++ Program to Perform a Letter Frequency Attack on a Monoalphabetic Substitution Cipher
Introduction: Monoalphabetic substitution ciphers have been in use for many years to hide and encode messages. In these ciphers, each letter in the plaintext is replaced with one fixed letter in the ciphertext. Even though, these ciphers are easy to grasp and apply but they are also...
6 min read
How does Duff's Device work in C++
? In the area of programming, inventive solutions to complex issues frequently emerge. Duff's Device is an excellent example of such an invention, notably in the area of efficient looping in the C and C++ programming languages. This technique, named after its author, Tom Duff, demonstrates a...
4 min read
Call By Value in C++
In this article, you will learn about the call by value in C++ with its mechanism, examples, advantages, and disadvantages. Introduction to Call by Value Passing the data to functions or methods is a common thing while programming. It allows you to modularize your code, reuse functionality, and...
5 min read
Std::nullopt in C++
In this article, you will learn about the std::nullopt function in C++ with their example. It was originally included in the C++17 standard. std::nullopt is a constant in C++ that is mostly used in conjunction with std::optional to indicate the lack of a value. Here are...
4 min read
C++ Program to Represent Linear Equations in Matrix Form
Linear Equation is a basic concept in mathematics and science. Linear equations are important in many disciplines, such as computer science, economics, physics, and engineering. It is necessary to express systems of linear equations in matrix form to solve them quickly. What is a System of Linear...
4 min read
Unsigned int in C++
The data types that only include integers as non-negative whole numbers are unsigned int. In contrast to C++ signed integers, unsigned int can only hold positive integers that can range from 0-255, which can hold both positive and negative whole numbers. As a result, it can...
4 min read
How to Split a String by Multiple Delimiters in C++
? Splitting the string in programming is a very common case. In solving many problems or optimizing the programs, programmers come across splitting the string. It can be done in many ways in C++. The different approaches will give different time and space complexity. This article will...
6 min read
Longest Common Subsequence with no Repeating Character in C++
The Longest Common Subsequence (LCS) problem is a classic dynamic programming problem that aims to find the length of the longest subsequence common to two given sequences. Algorithm: Initialize a 2D array (matrix): Create a 2D array dp with dimensions (m + 1) x (n + 1), where m...
7 min read
C++ Program to convert Decimal to Binary
We can convert any decimal number (base-10 (0 to 9)) into binary number (base-2 (0 or 1)) by C++ program. Decimal Number Decimal number is a base 10 number because it ranges from 0 to 9, there are total 10 digits between 0 to 9. Any combination...
1 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India
