Reverse a String in C Using Pointers – Three Approaches with Code

Reversing a string in C means rearranging its characters so the last character becomes the first and vice versa: “Hello” becomes “olleH”. The standard technique is the two-pointer swap — place one pointer at the start and one at the end, swap the characters they point to, then move the pointers toward each other until …

K&R C Exercise 1-19: Reverse a String in C

Exercise 1-19. Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input a line at a time. Approach The core algorithm is the classic two-pointer swap: place one index at the start of the string (i = 0) and one at the end (j = …

C program to check whether a given string is palindrome or not

A palindrome is a word, sentence, or sequence that reads the same forward and backward — ignoring differences in capitalization for word-level palindromes. Examples: “racecar”, “GADAG”, “level”, “9009”. The most efficient check uses a two-pointer approach: one pointer starts at the left end, one at the right, and they advance toward each other until they …