Program to reverse a string:
#include <cstring> // For using string functions
#include <iostream> // For I/O
using namespace std;
int revstr(char strr[]); // Corrected function signature
int main() {
char str[10];
cout << "Enter the string: ";
// Input the string
for(int i = 0; i < 9; i++) {
cin >> str[i];
// Reverse the string
revstr(str);
// Print the reversed string
cout << "The string reversed is: ";
for(int i = 0; i < 9; i++) {
cout << str[i];
return 0;
// Function to reverse the string
int revstr(char strr[]) {
int len = strlen(strr); // Find the length of the string
for(int i = 0; i < len / 2; i++) {
// Swap characters
swap(strr[i], strr[len - i - 1]);
return 0;
#include<iostream>
#include<cstring>
using namespace std;
2. to reverse a string
int main()
int arrsize;
cout<<"enter the len of the array size:";
cin>>arrsize;
char str1[arrsize];
cout<<"enter the string to be reversed:";
for(int i=0;i<arrsize;i++)
cin>>str1[i];
//to reverse the string using for loop
for(int i=arrsize;i>=0;i--)
cout<<str1[i];