Actions

EmSys

CCoding Style - Parenthesize to resolve ambiguity3

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Parenthesize to resolve ambiguity ...

Even if parenthesis aren’t necessary, they can help if the grouping is hard to grasp at first glance.

leap_year = y%4 == 0 && y%100 != 0 || y%400 == 0;

but they make it easier to understand:

leap_year = ( (y%4 == 0) && (y%100 != 0) || (y%400 == 0) );

Grouping the operands of higher precedence operators helps the reader to see the structure more quickly.