Reverse a String
In this example, you will learn and get the program code to print reverse string in c programming without using strrev (string reverse) function. Here we will be using only string length and for loop to do this program.
What is String?
A “string” is a sequence of characters (letters, numbers, symbols) used in programming to represent and manipulate text. It’s often enclosed in quotes and supports various operations.
Reverse String Logic
Input : HELLO
Output : OLLEH
Program of Reverse String in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> #include <string.h> int main(void) { char *str="CodeRevise"; printf("\nBefore Reverse the String:"); printf("%s",str); printf("\nAfter Reverse the String:"); for(int i=(strlen(str)-1);i>=0;i--) { printf("%c",str[i]); } return 0; } |
Output
Check out our other C programming Examples