Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Why does it suggest parentheses for the code snippet?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Walter Roberson, post: 2507810"] && binds more tightly than ||, so the test is equivilent to (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) However, it is relatively common for people to mistakenly think of && and || as having the same precedences, and so it is common for people to read the operators from left to right. It doesn't make a difference in this particular case, but if you had written, if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) then people would tend to (mistakenly) read this as if ((year % 400 == 0 || year % 4 == 0) && year % 100 != 0) when really it is if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) The warning is altering you to the possibility of the common misreading. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Why does it suggest parentheses for the code snippet?
Top