0

In the below example will the comparison between a and c be executed or will it be skipped? I would assume the answer is no because the value of valid has already been determined since if any comparison is false in this expression the resulting value of valid is false, but I don't actually know if that's true.

int i = 10, b = 20, c, 30;
bool valid = (i > b && a < c);

Thanks for taking the time to answer my question!

Liam Gallagher
  • 170
  • 1
  • 9
  • It's something related to short-circuit. Though I don't write c++, I think c++ has the same mechanism. – Light Aug 09 '20 at 02:16
  • 3
    TLDR; it depends. If `operator&&` is overloaded all comparisons will be evaluated. If it's not overloaded the evaluation is short-circuited. That's the reason `operator&&` and `operator||` shouldn't be overloaded as AND resp. OR operators. – Thomas Sablik Aug 09 '20 at 02:22

0 Answers0