📝⚡Beginner
Reverse an Array or String
Reverse string characters
Reverse a string by swapping characters from both ends.
Program Code
string_reverse.c
C
1#include <stdio.h>2#include <string.h>34int main() {5 char str[100];6 7 printf("Enter a string: ");8 scanf("%99s", str);9 10 int len = strlen(str);11 12 // Reverse using swap13 for (int i = 0; i < len / 2; i++) {14 char temp = str[i];15 str[i] = str[len - 1 - i];16 str[len - 1 - i] = temp;17 }18 19 printf("Reversed: %s\n", str);20 return 0;21}Output
Enter a string: Programming
Reversed: gnimmargorP
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials