- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reverse a string using the pointer in C++
This article reverse a string using the pointer in C++ coding, First, it calculates the length of a pointer to string then run a for loop in decrement order to display the reverse string as follows;
Example
#include <string.h> #include <iostream> using namespace std; int main(){ char *str="ajaykumar"; cout<<"original string::"<<str; cout<<endl<<"String after reverse::"; for(int i=(strlen(str)-1);i>=0;i--){ cout<<str[i]; } return 0; }
This above program prints the to be supplied string “ajaykumar” in reverse order as follows.
Output
Original string::ajaykumar String after reverse::ramukyaja
Advertisements