Reputation: 27
in "C Modern approach 2nd'ed " Are some exercises i can't understand the meaning. The result is 1, how do you read it ? Thank you.
#include <stdio.h>
int main(void)
{
int i, j, k;
i = 5;
j = 0;
k = -5;
printf("%d", i && j || k);
return (0);
}
Upvotes: 0
Views: 121
Reputation: 68
The operators ||(or) &&(and) named are bolean operators.
They return 0 or 1.
In order x&&y will return 1, it's necessary that x and y will be any number but 0. If at least one of them is equal to 0, it returns 0.
The operator || returns 1 if at least one of them is diffrent then 0, and 0 if they both qual to 0.
Upvotes: 1
Reputation: 145829
i && j || k
is equivalent to
(5 && 0) || -5
equivalent to
0 || -5
equivalent to 1
.
Logical operators yield a value of 0
or 1
.
Upvotes: 7