(*s++ - '0') this will subtract ascii value of stored character with ascii value of 0 and will give numeric (decimal ) value of stored character during each iteration,
example: ascii value of 0 and 1 is 48 and 49 , hence during iteration 1:
(*s++ - '0')=s[0]-'0'='0'-'0'=48-48=0(decimal value)
now evaluation of ur program is as given below : fun("000001010")
iteration |
r<<1 |
(*s++-'0')=value stored at s[i] |
r = r<<1|(*s++ - '0') |
1 |
0 |
0 |
0 |
2 |
0 |
0 |
0 |
3 |
0 |
0 |
0 |
4 |
0 |
0 |
0 |
5 |
0 |
0 |
0 |
6 |
0 |
1 |
1 |
7 |
2 |
0 |
2 |
8 |
4 |
1 |
5 |
9 |
10 |
0 |
10 |
10 |
|
\n(ascii value 0) |
loop fail |
therefore 10 will be return at the end