Possible Duplicate:
Is short-circuiting boolean operators mandated in C/C++? And evaluation order?
Is there any defined by standard or math rules order of eveluating boolean sentences? For example:
if (firstTrue && secondTrue)
{
}
can I be sure that firstTrue will be checked first?
Yes.
&&and||are short circuiting operators. The order of evaluation of operands is well defined (left to right).&&is also a sequence point.So writing
if( ++i && i) { }is perfectly fine.ISO C++03 (
5.14/1) says:EDIT: (After seeing the comment)
ISO C++03 (Section
1.9/18) says