prev up next   top/contents search

comp.lang.c FAQ list · Question 3.5

Q: But what about the && and || operators?
I see code like ``while((c = getchar()) != EOF && c != '\n')'' ...

A: There is a special ``short-circuiting'' exception for these operators: the right-hand side is not evaluated if the left-hand side determines the outcome (i.e. is true for || or false for &&). Therefore, left-to-right evaluation is guaranteed, as it also is for the comma operator (but see question 3.7). Furthermore, all of these operators (along with ?:) introduce an extra internal sequence point (see question 3.8).

References: K&R1 Sec. 2.6 p. 38, Secs. A7.11-12 pp. 190-1
K&R2 Sec. 2.6 p. 41, Secs. A7.14-15 pp. 207-8
ISO Sec. 6.3.13, Sec. 6.3.14, Sec. 6.3.15
H&S Sec. 7.7 pp. 217-8, Sec. 7.8 pp. 218-20, Sec. 7.12.1 p. 229
CT&P Sec. 3.7 pp. 46-7

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North