What is the procedure for evaluating a Boolean sentence?

Possible duplicate:
Are short-circuiting boolean operators provided for in C / C ++? And the evaluation procedure?

Is there any standard order or mathematical order for extracting Boolean sentences? For instance:

if (firstTrue && secondTrue)
{
}

Can you be sure that firstTrue will be checked first?

+3
source share
3 answers

Yes. &&and || short circuit operators . The order in which operands are evaluated is clearly defined (from left to right).

&&also a point of sequence.
Therefore, writing is if( ++i && i) { }excellent.

ISO C ++ 03 ( 5.14/1) says:

& & . bool ( 4). , false . && & : , .

EDIT: ( )

ISO ++ 03 ( 1.9/18)

a &&
a ||
a? b: c
a, b

(5.14, 5.15, 5.16, 5.18), .

+10

firstTrue. , firstTrue , True . .

: http://en.wikipedia.org/wiki/Short-circuit_evaluation

||. || true, .

+6

. "" ( )

&& ( ||) : , . LHS RHS. RHS, LHS. ( , ), .

&& ||. && || .

+2

Source: https://habr.com/ru/post/1766553/


All Articles