c - Evaluation of logical operand -


if have following:

int = -10 && 0; 

then c evaluate -10 1 because -10 different 0 , make comparation between 1 && 0 0 result? or let -10 , make comparation written?

instead if write:

int c = 10; int b = 11;  int res = c > 10 && b == 11; 

then c make this:

c > 10 false evaluates 0 while b == 11 true evaluates 1

then expression is:

0 && 1 0 result.

the operator && , || has short circuit behavior1. in

int = -10 && 0;   

since left operand -10, non-zero , hence true, therefore right operand, i.e 0 checked. in

int res = c > 10 && b == 11;   

since left operand evaluated false, right operand not evaluated.


1 c11 6.5.13 (p4): if first operand compares equal 0, second operand not evaluated.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -