This is the image of my code I am a newbie who was trying to write a code to reverse a number but only number till 9/10 digits is working fine else giving strange answers
Looks at a first input, I am sure the reverse isn't true but the second one is giving right why ??
CodePudding user response:
Your number is limited to INT_MAX
value, and is likely to be limited to 32 bit.
For 32 bit platforms INT_MAX
value is ((1 << 31) - 1) = 2147483647
which has 10 digits
When the user inputs a number greater than INT_MAX
it is overflowed and the value shouldn't be what the user gave as input
If you want to extend the number range, you can use long long
or unsigned long long
types on 64 bit platforms, but then you'll be limited to 64 bit numbers
Another approach is to implement a BigInt
class (the same as in Java) which has no limitation on the bit size (There are several opensource implementations for this kind of class).