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

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

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -