C++ lazy evaluation of boolean or in function call expression
c++, lazy-evaluation
Solution
In C/C++ the logical operators short-circuit. In `a || b` if `a` is true `b` is not evaluated and in `a && b` if `a` is false `b` is not evaluated.
Careful: this only happens with `&&` and `||`, not with `|` and `&`.
Problem
Quick question, in c++ is this expression lazily evaluated? ``` bool funca(); bool funcb(); funca() || funcb(); // line in question ``` Obviously this is (potentially) just shorthand for the following: ``` bool funca(); bool funcb(); if (!funca()) { funcb(); } // or even more concisely: if (!funca()) funcb(); ``` Will c++ evaluate that original line in question as I'm hoping it will? Thanks.