Answer to Question #240818 in C++ for Zeeshan

Question #240818
Write a program that inputs a string value from the user and displays it in reverse
using pointer.
1
Expert's answer
2021-09-22T23:44:08-0400
#include <iostream>
#include <string.h>
using namespace std;




void reverseing(char* st)
{
    int size, i;
    char *begin, *end, ch;
  
   
    size = strlen(st);
  
    
    begin= st;
    end = st;
  
    
    for (i = 0; i < size - 1; i++)
        end++;
  
    
    for (i = 0; i < size / 2; i++) {
  
        
        ch = *end;
        *end = *begin;
        *begin = ch;
  
        
        begin++;
        end--;
    }
}
  




int main()
{
  
   
    char str[100];
    cout<<"Enter a string:\n";
    cin>>str;
  
    
    reverseing(str);
  
  
    cout<<"The reverse string is: %s\n"<<str;
  
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS