+ 6

Can I conclude that bool can even analyze strings as true or false?

https://www.sololearn.com/discuss/550449/?ref=app The following problem I had the day before yesterday was solved only when I interchanged the bool and the int parameters in the first constructor... Thus I think that the bool data type was also reading strings and analyzing it, as the 1st constructor was being invoked... So, why is this happening? How does bool analyze a string as true or false? Is it based on size? Or on first character?

22nd Jul 2017, 4:37 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
4 Answers
+ 11
any value that is not 0 is considered true.
22nd Jul 2017, 4:40 AM
jay
jay - avatar
+ 5
@jay Wow. Even an empty string is shown as true...
22nd Jul 2017, 5:42 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
@Jay Ok. So what string can be rendered false?
22nd Jul 2017, 4:43 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar