basics · beginner · ~15 min
Compare characters with two converging pointers.
Decide whether a string reads the same forwards and backwards.
Implement int is_palindrome(const char *s) that returns 1 if s is a palindrome (identical when reversed), else 0. Use two indices converging from each end, comparing characters. Compare characters exactly — no case-folding or skipping. No main — the grader calls it.
A NUL-terminated string s.
Returns 1 if s is a palindrome, otherwise 0.
is_palindrome("racecar") -> 1
is_palindrome("aa") -> 1
is_palindrome("abc") -> 0
is_palindrome("") -> 1
A NUL-terminated string s.
1 if s is a palindrome, otherwise 0.
Compare characters exactly; the empty string is a palindrome.
#include <string.h>
int is_palindrome(const char *s) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.