Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Program to Reverse a String using Pointers

  • Difficulty Level : Medium
  • Last Updated : 12 Jan, 2019

Given a string, the task is to reverse this String using pointers.


Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.
Input: Geeks
Output: skeeG

Input: GeeksForGeeks
Output: skeeGroFskeeG

Approach: 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.


#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);
    // Set the begin_ptr and end_ptr
    // initially to start of string
    begin_ptr = str;
    end_ptr = str;
    // Move the end_ptr to the last character
    for (i = 0; i < l - 1; i++)
    // 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
// Driver code
int main()
    // Get the string
    char str[100] = "GeeksForGeeks";
    printf("Enter a string: %s\n", str);
    // Reverse the string
    // Print the result
    printf("Reverse of the string: %s\n", str);
    return 0;
Enter a string: GeeksForGeeks
Reverse of the string: skeeGroFskeeG

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!