c - Associativity interpretation? -
in c operators left-associative , right associative, left-associative operator example starts left side , ends on right of user.
if example in case of assignment operator x=y;
x=5
, y=20
, saying put value of y
in x
, seems legitimate.
but in cases if(x>y)
, '>` operator has left associativity. means computes is x greater y? false.
but, why go can reading right associativity is y smaller x? false
why use left associativity when output comes same in both cases?
for ternary operation mat says.
the answer x>y>z
depends on direction, answer vary right left , left right. because of different comparisons done @ different stage.
both answers evaluate value, why chose 1 left associativity
the associativity concept come in play when expression has more 1 operator. property of operator in expression, not operands. define how brackets inserted, not operator means.
operator : r expression : x r y r z left right : (x r y) r z right left : x r (y r z)
Comments
Post a Comment