Trouble understanding what this code does

Hello there,
I am doing a program to check if a number is a palindrome or not.i have trouble understanding what the following does.it would be a great help if you could answer.thanks in advance.

cout<<"Enter any Number:";
cin>>n;
num=n;
do
{
d=n%10;
rev=(rev*10)+d;
n=n/10;
}while(n!=0);
Last edited on
The answer is probably "42", because
1. The code sets value for variable 'num' that is not used anywhere.
2. The initial value of variable 'rev' is not known


1
2
3
4
5
6
7
8
9
cout << "Enter any Number:";
cin >> n;
num = n;
do
{
  d = n % 10;
  rev = (rev*10) + d;
  n = n / 10;
} while ( n!=0 );

While you don't understand all of the code, you must understand some of it.

1. Start by explaining each statement that you do know.

2. Let me give you a test input: "24". n==24 at start.
Evaluate the code statement by statement and keep record of the values of all variables.
Topic archived. No new replies allowed.