A palindrome number reads the same forwards and backwards. Classic examples: 121, 3443, and every one-digit value.
Remember
n is palindrome ⇔ reverse(digits of n) == n
Examples:
121 → reverse 121 → yes
123 → reverse 321 → no
7 → reverse 7 → yes
10 → reverse 01=1 → no
n
Reverse
Palindrome?
121
121
Yes
1221
1221
Yes
123
321
No
Approach
How to Check a Palindrome Number in C
Four clear steps — then pick a math reverse or a buffer compare.
Reject negatives for this beginner rule.
Copy n into a temporary variable.
Build the reverse: repeatedly take digit = temp % 10, then rev = rev * 10 + digit, then temp /= 10.
Compare rev with the original n.
Method
Idea
Time
Best for
Digit reverse
Build rev with % 10 / / 10
O(d)
Interviews (pure arithmetic)
Buffer compare
Compare digits left vs right
O(d)
Clear two-pointer reasoning
Pseudocode
Pseudocode
function IsPalindrome(n):
if n < 0:
return false
original = n
rev = 0
while n > 0:
digit = n mod 10
rev = rev * 10 + digit
n = n / 10
return rev == original
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Core idea
Reverse digits, then compare
Digit peel
n % 10 then n /= 10
Build reverse
rev = rev * 10 + digit
One digit
Always palindrome
Negatives
Usually not (this page: false)
Classic checks
121 yes; 123 no; 10 no
Try it
Live Preview
Enter an integer to see the reversed digits and the palindrome check.
Whole numbers only. Negatives count as not palindrome here. Tap a chip or type a value.
Result
n = 121
Reverse = 121
121 is a palindrome
Trace
Worked Walkthrough — n = 121
Peel digits from the right and push them onto the reverse value.
Calculation
original = 121
rev = 0
Step 1: digit = 1, rev = 0*10 + 1 = 1, n = 12
Step 2: digit = 2, rev = 1*10 + 2 = 12, n = 1
Step 3: digit = 1, rev = 12*10 + 1 = 121, n = 0
rev == original → 121 is a palindrome
Code
C Programs
Start with the math reverse — interviewers usually want that. Use the buffer version when two-pointer comparison feels clearer.
Example 1 — Digit Reverse
Build the reverse integer with remainder and integer division, then compare.
C
#include <stdio.h>
int is_palindrome(int n)
{
int original;
int rev = 0;
if (n < 0)
{
return 0;
}
original = n;
while (n > 0)
{
int digit = n % 10;
rev = rev * 10 + digit;
n /= 10;
}
return rev == original;
}
int main(void)
{
int number = 121;
if (is_palindrome(number))
printf("%d is a palindrome\n", number);
else
printf("%d is not a palindrome\n", number);
return 0;
}
Output
121 is a palindrome
How It Works
Negatives return false immediately under this page’s rule.
Save original because the loop will destroy the working copy of n.
Each step peels the last digit with n % 10 and appends it to rev.
n /= 10 drops that digit so the loop moves leftward.
When the loop ends, rev == original means the digits matched both ways.
Example 2 — Buffer Compare
Write digits into a char buffer and compare left and right indices.
C
#include <stdio.h>
int is_palindrome(int n)
{
char s[16];
int len;
int i;
if (n < 0)
{
return 0;
}
len = sprintf(s, "%d", n);
for (i = 0; i < len / 2; i++)
{
if (s[i] != s[len - 1 - i])
{
return 0;
}
}
return 1;
}
int main(void)
{
printf("%d\n", is_palindrome(121)); /* 1 */
printf("%d\n", is_palindrome(123)); /* 0 */
printf("%d\n", is_palindrome(7)); /* 1 */
printf("%d\n", is_palindrome(-121)); /* 0 */
return 0;
}
Output
1
0
1
0
How It Works
Same negative rule as Example 1.
sprintf writes the digits into a character buffer.
Compare s[i] with s[len - 1 - i] from the outside in.
Any mismatch returns false; finishing the loop means it is a palindrome.
Same answers as the math method; use digit reverse when you must avoid string helpers.
Edge Cases & Pitfalls
Check these before calling the solution done.
0–9
Single digits
Always palindromes. The reverse loop still works.
Negatives
Usually false
The minus sign breaks left-to-right equality. Confirm the problem’s rule.
Trailing 0
Like 10
Integer reverse drops leading zeros, so 10 becomes 1 — not a palindrome.
Overflow
Huge reverses
Reversing a near-INT_MAX value can overflow. Prefer long for rev if needed.
Analysis
Time and Space Complexity
Program
Time
Extra space
Digit reverse
O(d)
O(1)
Buffer compare
O(d)
O(d)
Here d is the digit count. Both scan the digits once; the buffer method stores the digit characters.
Remember
Key Takeaways
Definition: digits match forwards and backwards.
Loop:rev = rev * 10 + (n % 10), then n /= 10.
Compare:rev == original (or left/right buffer indices).
Test set: 121 → yes; 123 → no; 7 → yes; 10 → no.
One line: reverse the digits and check equality with the original number.
Frequently Asked Questions
A number that reads the same forwards and backwards, such as 121 or 3443. Single-digit numbers are always palindromes.
Reverse the digits with % 10 and / 10, then compare the reverse with the original — or write digits into a buffer and compare left and right indices.
Usually no for interview problems, because of the leading minus sign. This page treats n < 0 as not a palindrome.
Numbers like 10 reverse to 01, which is 1 as an integer, so they are not palindromes.
Both methods are O(d), where d is the number of digits. Extra space is O(1) for the math reverse and O(d) for the buffer method.