I have a question about a part of the getint program.
When we got this part:
for(*pn = 0; isdigit(c); c = getch())
*pn = 10 * *pn + (c - '0');
First it converts c to its real numeric value, then it multiply the data inside pn with 10.
Why does it multiply 10 with the data inside pn?
Regards,
Ken
It is starting from the left, and multiplying by 10 for each successive digit it encounters as it moves to the right.
Take the string “234” for example:
*pn) by 10, add 2, you get 2.*pn) by 10, add 3, you get 23.*pn) by 10, add 4, you get 234.