views:

61

answers:

1

On http://groups.google.co.in/group/comp.lang.c/browse_thread/thread/bfb312ad902d94eb/74dcdcacce777679?lnk=gst&q=conditional+operator#74dcdcacce777679

There is an answer given for a question why
(A%2==0)?A=0:A=1 gives error.

The thing I don't understand that when do we use (precedence and associativty) and we
use C grammar to parse the expression ?

+4  A: 

Always use the grammar to parse expressions.

Precedence and associativity are derived from the grammar, they are not the rules. Many precedence tables are over-simplifications that don't work in some obscure corner cases.

Charles Bailey
Can you give some examples where this would make difference i.e precedence and grammar cross each other as it is pretty difficult to learn grammar as compared to precedence of operators.
Happy Mittal
As your example shows, any table that tries to put `?:` somewhere is usually misleading as the all three operands have different expression types. You can have an _assignment-expression_ in the middle but not (in C; not C++) the end.
Charles Bailey