0

How || is functioned when it is used for two numbers??

https://code.sololearn.com/cSmX7OQGm5pF/?ref=app

6th Feb 2018, 8:57 AM
Pardha saradhi Chodey
Pardha saradhi Chodey - avatar
2 Answers
+ 2
the numbers are implicitly converted to booleans. 0 becomes false, all other nuns are true. then they undergo logical or operation.
6th Feb 2018, 9:05 AM
DAB
DAB - avatar
0
In C (and C++) a zero value is false, anything else is true. https://en.wikipedia.org/wiki/C_data_types#Boolean_type Logical OR operator (||) returns false only if both operands are false, and true if any of the operands or both of them are true. So, in your example, i||j is 4||-1, which is true||true, which returns true. When a value is interpretted as a logical value (boolean), it becomes 1 if it is true, and 0 is it is false ("any assignments to a _Bool that are not 0 (false) are stored as 1 (true)" — wiki). So 1 gets printed out.
6th Feb 2018, 9:11 AM
deFault