Program to Reverse a String using Pointers Last Updated : 07 Aug, 2024 Comments Improve Suggest changes Like Article Like Report Given a string, the task is to reverse this String using pointers. Examples:Input: GeeksOutput: skeeGInput: GeeksForGeeksOutput: skeeGroFskeeGApproach: This method involves taking two pointers, one that points at the start of the string and the other at the end of the string. The characters are then reversed one by one with the help of these two pointers. Program: C++ #include <bits/stdc++.h> using namespace std; void reverseString(char* str) { int l, i; char *begin_ptr, *end_ptr, ch; // Get the length of the string l = strlen(str); // Set the begin_ptr // initially to start of string begin_ptr = str; // Setting end_ptr initially to // the end of the string end_ptr = str + l - 1; // Swap the char from start and end // index using begin_ptr and end_ptr for (i = 0; i < l / 2; i++) { // swap character ch = *end_ptr; *end_ptr = *begin_ptr; *begin_ptr = ch; // update pointers positions begin_ptr++; end_ptr--; } } int main() { // Define a string char str[100] = "GeeksforGeeks"; cout << "Original String: " << str << endl; // Reverse the string reverseString(str); cout << "Reverse of the string: " << str << endl; return 0; } C #include <stdio.h> #include <string.h> // Function to reverse the string // using pointers void reverseString(char *str) { int l, i; char *begin_ptr, *end_ptr, ch; // Get the length of the string l = strlen(str); // Setting the begin_ptr // to start of string begin_ptr = str; // Setting the end_ptr the end of // the string end_ptr = str + l - 1; // Swap the char from start and end // index using begin_ptr and end_ptr for (i = 0; i < l / 2; i++) { // swap character ch = *end_ptr; *end_ptr = *begin_ptr; *begin_ptr = ch; // update pointers positions begin_ptr++; end_ptr--; } } int main() { // Define the String char str[100] = "GeeksforGeeks"; // Reverse the string reverseString(str); printf("Reverse of the string: %s\n", str); return 0; } OutputEnter a string: GeeksForGeeks Reverse of the string: skeeGroFskeeGTime Complexity: O(N), where N represents the length of the given string.Auxiliary Space: O(1), no extra space is required, so it is a constant. Comment More infoAdvertise with us Next Article Program to Reverse a String using Pointers C code_r Follow Improve Article Tags : C Language cpp-pointer C-String Similar Reads Program to reverse an array using pointers Prerequisite : Pointers in C/C++ Given an array, write a program to reverse it using pointers . In this program we make use of * operator . The * (asterisk) operator denotes the value of variable . The * operator at the time of declaration denotes that this is a pointer, otherwise it denotes the val 4 min read C Program to Reverse Array of Strings Given an array of string literals, reverse the array. Examples: Input : arr[] = {"Coding", "Never", "Fail", "Me"} Output : arr[] = {"Me", "Fail", "Never", "Coding"} Input : arr[] = {"welcome", "to", "geeksforgeeks"} Output : arr[] = {"geeksforgeeks", "to", "welcome"} The idea is to create an array o 1 min read Reverse a string in C/C++ using Client Server model This article describes a Client and Server setup where a Client connects, sends a string to server and the server shows the original string and sends reversed string to client using socket connection. Prerequisite : Socket Programming Examples: Input : welcome Output :emoclew Input :geeks for geeks 3 min read Check if a string is palindrome in C using pointers Given a string. The task is to check if the string is a palindrome or not using pointers. You are not allowed to use any built-in string functions. A string is said to be a palindrome if the reverse of the string is same as the original string. For example, "madam" is palindrome because when the str 2 min read Get a Substring in C A substring is a contiguous sequence of characters within a string. In this article, we will learn how to extract a substring using a C program.The simplest method to get a substring from a larger string is by using strncpy() function. Letâs take a look at an example:C++#include <stdio.h> #inc 2 min read Like