How to reverse a string in C?
#include <stdio.h>
#include <string.h>
int main(void) {
char s[] = "Hello";
int i = 0, j = strlen(s) - 1;
while (i < j) {
char t = s[i];
s[i] = s[j];
s[j] = t;
i++;
j--;
}
printf("%s\n", s);
return 0;
}
Output:
Output of the above program is
olleH
More ways are in Reverse a String in C.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |