How do C++ operators work -


given x = 2, y = 1, , z = 0, following statement display?

printf("answer = %d\n", (x || !y && z)); 

it on quiz , got wrong, don't remember professor covering this, enlighten me please... know answer 1, why?

the expression interpreted x || (!y &&z)(check out precedence of operators ||, ! , &&.

|| short-circuiting operator. if left operand true (in case of ||) right side operand need not evaluated.

in case x true, being boolean expression result 1.

edit.

the order of evaluation of && , || guaranteed left right.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -