UCSB Science Line
Sponge Spicules Nerve Cells Galaxy Abalone Shell Nickel Succinate X-ray Lens Lupine
UCSB Science Line
Home
How it Works
Ask a Question
Search Topics
Webcasts
Our Scientists
Science Links
Contact Information
In c++ when we have an a && b, then if a is false, b isn't considered. Does something similar happen when we have a && b &&c?
Question Date: 2021-11-13
Answer 1:

When using short-circuiting operators (&& and || as opposed to bitwise & and |), evaluation stops once the result is determined. And with logical operators, C++ evaluates from left to right. This means that in the example of a && b && c, evaluation could stop at a, at b, or require evaluating and comparing all three a, b, and c. However, it won't check b && c before evaluating a.

(References - cplusplus midway down page , cppreference: Rule #6)



Click Here to return to the search form.

University of California, Santa Barbara Materials Research Laboratory National Science Foundation
This program is co-sponsored by the National Science Foundation and UCSB School-University Partnerships
Copyright © 2020 The Regents of the University of California,
All Rights Reserved.
UCSB Terms of Use