Program to Reverse a String using a Pointers In C

Share Your Love

Suppose there is a string and we reverse a string using a pointers in C. Let’s see how is it possible through a pointer. So before proceed we take a little bit of knowledge about pointers here.


Input: LingarajTechhub
Output: buhhcdtjaragniL

Input: Qwerty
Ouput: ytrewQ


This approach requires two pointers, one pointing to the beginning of the string and the other pointing to the end of the string. With the help of these two pointers, the characters are then inverted one by one.


#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: LingarajTechhub
Reverse of the string: buhhcdtjaragniL

Share Your Love
Avatar photo
Lingaraj Senapati

Hey There! I am Lingaraj Senapati, the Founder of My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.

Articles: 429

Newsletter Updates

Enter your email address below to subscribe to our newsletter