If you're learning C programming, reversing a string is one of those basic but useful problems that helps you understand how strings and arrays work. It's a common question in exams and interviews too.
In this article, we’ll go through a few easy ways to reverse a string in C. By the end, you’ll have a clear understanding of how the logic works. Also, if you're thinking about taking your coding skills further, there’s a suggestion for you at the end.


It simply means changing the order of characters in a string so that the first character becomes the last, and so on.
Example:
Now let’s look at how you can write a program to do this in C.
This is the most straightforward way. We copy the characters from the original string into another array in reverse order.
#include#include int main() { char str[100], rev[100]; int len, i, j; printf("Enter a string: "); gets(str); // Note: gets() is outdated, use fgets() in real programs len = strlen(str); j = 0; for(i = len - 1; i >= 0; i--) { rev[j++] = str[i]; } rev[j] = '\0'; // End the string properly printf("Reversed string: %s\n", rev); return 0; }
This method saves memory by doing everything in the original string itself.
#include#include int main() { char str[100]; int i, len; char temp; printf("Enter a string: "); gets(str); len = strlen(str); for(i = 0; i < len / 2; i++) { temp = str[i]; str[i] = str[len - i - 1]; str[len - i - 1] = temp; } printf("Reversed string: %s\n", str); return 0; }
This is faster and uses less memory than the first method.
If you're comfortable with pointers, this is a cool way to reverse strings.
#include#include void reverseString(char *str) { char *start, *end, temp; start = str; end = str + strlen(str) - 1; while(start < end) { temp = *start; *start = *end; *end = temp; start++; end--; } } int main() { char str[100]; printf("Enter a string: "); gets(str); reverseString(str); printf("Reversed string: %s\n", str); return 0; }
If you enjoy programming and want to build full websites or applications, learningFull Stack Development is a great next step.
AFull Stack Developerknows both:
You’ll learn things like:
There are many online Full Stack Developer courses that are beginner-friendly and include projects and certifications. If you're already good with C, you'll find learning web development even easier.
Reversing a string in C might be simple, but it helps you learn the basics of loops, arrays, and pointers. Try all three methods and see which one makes the most sense to you.
And if you're serious about programming, don’t stop at C. Learn how to build complete applications and explore full stack development. It’s a great way to grow your skills and open up career opportunities.
Personalized learning paths with interactive materials and progress tracking for optimal learning experience.
Explore LMSCreate professional, ATS-optimized resumes tailored for tech roles with intelligent suggestions.
Build ResumeDetailed analysis of how your resume performs in Applicant Tracking Systems with actionable insights.
Check ResumeAI analyzes your code for efficiency, best practices, and bugs with instant feedback.
Try Code ReviewPractice coding in 20+ languages with our cloud-based compiler that works on any device.
Start Coding
TRENDING
BESTSELLER
BESTSELLER
TRENDING
HOT
BESTSELLER
HOT
BESTSELLER
BESTSELLER
HOT
POPULAR