*pn = 10 * *pn + c - '0';
Use parenthesis to help to understanding the pointers use.
In my case, I use this conversion to understand the pointer usage:
*pn = (10) * (*pn) + (c - '0');
pn[0] = (10) * (pn[0]) + (c - '0');
The point here is separate the usage of the pointer from the declaration of the pointer variable.
The function contains various parts:
- c - '0' is a hack to convert from ASCII number to their numerical form. The hex code of ASCII characters says that the hex value of 0x30 belongs to the character '0', the 0x31 is the character '1', and so on. This is a hack because it implies you are using ASCII notation to receive the "numbers"
The second part, the multiplication, comes before the adding, so 10 * (pn[0]) says you are moving a digit to the left and adding a 0. Visually, it means:
10 * (the value of the first pn) = the partial result
(10) * (pn[0]) = partial_result
(10) * ( 5) = 50
(10) * (17362) = 173620
This is the mathematical translation of "displace to the left in decimal notation"
The last part is the joining of both:
The value you received from c (the character) and the value you displaced to the left