1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
while (number>0) // while the int value number is greater than 0
{
temp+=number%10+48; // 48 is the ASCII code for '0'
// as '1', '2', '3', ... follow on, adding 1, 2, 3, ...
// to 48 give the ASCII code for the chars '1', '2', '3', ...
//
// number%10 is the remainder when dividing number
// by 10, which means the units (which are 0-9)
//
// temp is a string variable, which has an operator+=(char)
// which appends the char to the end of the string
//
// so temp+=number%10+48; is appending the char corresponding
// to the last digit of number to the string temp
number/=10; // divide number by 10 (as it's integer division, the remainder
// is thrown away, so after enough divisons number will be 0
// terminating the while loop)
}
|