0
String compare
Hi Why below code results into -32? string s1={"Hello Sololearn"}; string s2={"Hello solo"}; cout << s1.compare(s2);
3 Respostas
+ 5
Vijay Raj Jain isn't S in s1 smaller than s in s2? That's why 83-115 =-32 is returned!
0
0 : if both strings are equal.
a value < 0 : if *this is shorter than str or, first character that doesn't match is smaller than str.
a value > 0 : if *this is longer than str or, first character that doesn't match is greater
Since s2<s1 so value returned is -32
0
So -5 may be
1. difference between number of characters difference in string
2. Difference between first mismatch character's ASCII value
Is above right?