Friday, 15 January 2010

c++ - Multiple OR or AND conditions in IF statement -



c++ - Multiple OR or AND conditions in IF statement -

i having basic uncertainty regarding if statement. let's want match string sun character array(size 3).

if(arr[0]!='s' || arr[1]!='u' || arr[2]!='n') cout << "no"; else cout<< "yes";

are conditions checked in if statement or homecoming true on first mismatch?

if conditions checked, the order of checking right left?

according c++ standard

1 the && operator groups left-to-right. operands both contextually converted bool (clause 4). result true if both operands true , false otherwise. unlike &, && guarantees left-to-right evaluation: the sec operand not evaluated if first operand false.

and

1 the || operator groups left-to-right. operands both contextually converted bool (clause 4). returns true if either of operands true, , false otherwise. unlike |, || guarantees left-to-right evaluation; moreover, the sec operand not evaluated if first operand evaluates true.

c++ if-statement

No comments:

Post a Comment