C++ Program to Reverse a String without using System Defined method
In this tutorial, we will learn how to demonstrate how to find the reverse of the String without using the System Defined method, in the C++ programming language.
Steps to find Reverse of a String:
Take the String to be reversed as input.
Initialize another array of characters of the same length to store the reverse of the string.
Traverse the input string from its end to the beginning and keep storing each character in the newly created array of char.
using namespace std;
cout << "\n\nWelcome to Studytonight :-)\n\n\n";
cout << " ===== Program to Reverse the String without using System defined function, in CPP ===== \n\n";
char s1, c = 'a';
int n = 0, i = 0;
cout << "\n\nEnter the String you want to reverse: ";
cin >> s1;
//Computing string length without using system defined method
while (c != '\0')
c = s1[i];
n = i - 1;
cout << "\n\nLength of the entered string \"" << s1 << "\" is : " << n << "\n\n\n";
//Declaring another char array to store the reverse of the string
i = 0;
//Logic to store the reverse of a string in another char array
while (i != n + 1)
s2[i] = s1[n - i - 1];
cout << "\n\nReverse of the entered string \"" << s1 << "\" is : \"" << s2 << "\"\n\n\n";
We hope that this post helped you develop a better understanding of the concept of finding the reverse of the string without using the system-defined method in C++. For any query, feel free to reach out to us via the comments section down below.
Keep Learning : )