Evaluation Order in a Condition statement

D

David Côme

Hello.

Let A and B be 2 boolean expressions.
In the instruction if(A && B){/*..*/}, does the standard certify that A
will be evaluated first ?

Thanks a lot.
 
C

Christopher

Hello.

Let A and B be 2 boolean expressions.
In the instruction if(A && B){/*..*/}, does the standard certify that A
will be evaluated first ?

Thanks a lot.

left to right
 
P

Paavo Helde

Hello.

Let A and B be 2 boolean expressions.
In the instruction if(A && B){/*..*/}, does the standard certify that A
will be evaluated first ?

Even more: if A yields false, B is not evaluated at all.
 
R

red floyd

David said:
Hello.

Let A and B be 2 boolean expressions.
In the instruction if(A && B){/*..*/}, does the standard certify that A
will be evaluated first ?

I believe it depends upon whether operator&& is user-defined.
For built-in &&, yes, A is evaluated first, and B will not be evaluated
at all, if A is true.

For user defined &&, I believe the order is unspecified, and that both A
and B will be evaluated.
 
V

Victor Bazarov

Erik said:
Short circuit evaluation, lazy evaluation is something else.

And actually in 'A && B' the expression 'B' is *not* evaluated at all
if 'A' yields 'false'.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,222
Latest member
patricajohnson51

Latest Threads

Top