Reversing a String
Implementation of reversing a string without using library function.
Procedure :
C Function :
void reverse(char a[], int n) {
// Initialise i with 0 and j with length - 1
int i = 0, j = n-1;
char temp;
// Swap characters in each iteration
for (i = 0, j = n-1; i < j; i++, j--) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
Last updated