Conditional expressions are always evaluated to 0 or 1 in C?

An expression condition such as those that include && and || Are they always evaluated at 0 or 1? Or are numbers other than 1 possible for the true state? I ask because I want to assign such a variable.

int a = cond1 && cond2;

I was wondering if I should do the following.

int a = (cond1 && cond2)? 1:0;
+5
source share
2 answers

Logical operators ( &&, ||and !) evaluate either 1, or 0.

C99 §6.5.13 / 3:

&& 1, 0; 0. int.

C99 §6.5.14/3:

|| 1, 0; 0. int.

C99 6.5.3.3/5:

! 0, 0, 1, 0. int. ! E (0 == E).

+14
'&&'
  The logical-AND operator  produces the value 1 if both operands have nonzero 
  values. If   either operand is equal to 0, the result is 0. If the first operand of a 
  logical-AND operation is equal to 0, the second operand is not evaluated. 

'||'
      The logical-OR operator performs an inclusive-OR operation on its operands. 
  The result  is 0 if both operands have 0 values. If either operand has a nonzero
  value, the result is 1. If the first operand of a logical-OR operation has a nonzero 
  value, the second operand is not evaluated. 

OR . , . " ". .

,:)

0

All Articles