+ 2

What is difference between two programs in c++?

string s; cin>>s; cout<<(s[0])*10; string s; cin>>s; cout<<(s[0]-'0')*10; both produce different answers while input is a number suppose if input is 2756 the first program gives 550 the second one gives 70 why?

22nd Dec 2016, 3:06 PM
Anvesh
Anvesh - avatar
1 Respuesta
0
i guess your input start from 7 not from 2. lets take 7 . ascii value of 0 is 48 and ascii value of 7 is 55. lets take fist one s[0]= 7 then ascii of 7 is 55*10=550 second one s[0】-'0'=55-48=7 7*10=70
22nd Dec 2016, 6:49 PM
himanshu yadav
himanshu yadav - avatar