+ 1
Arithmetic operations with '0' c++
Please anyone explain me this row of code I found in the code of "addition of binary string" Int sum =a[i]-'0'+(b[i]-'0')+flag;
2 Respostas
+ 1
It would be better, if you provide some more information about the values for a[i], [b[i], flag to understand what logic they are using..
So that some one give you better answer..
As far my knowledge, there '0' is charecter value. And when used with arithmatics operators +, -,.. It will be converted to equalent (int) ascii value..
So 0 ascii value is 48.
And it subtracted from a[i], and b[i] and added to flag value... Result is in sum...
sum=(a[i] - 48)+(b[i]-48)+flag;
Hoping it helps you...
[Note: may be different, if a[i], b[i] are charecters.. depends on logic..]
Read about ascii values here..
https://www.quora.com/What-is-the-ASCII-code-for-digits-or-numbers
https://www.techonthenet.com/ascii/chart.php
+ 1
As stated, calculating that difference is most meaningful when a[] and b[] are char arrays containing the character representations of numerals.