By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,468 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

left to right associativity

P: 5
please dont mind the odd title. Its just for the sake of easyily locating that i choose the above.
Well, my problem is with left to right associativity.
please explain how it works.
Jun 11 '07 #1
Share this Question
Share on Google+
4 Replies


10K+
P: 13,264
please dont mind the odd title. Its just for the sake of easyily locating that i choose the above.
Well, my problem is with left to right associativity.
please explain how it works.
Ufortunately the guidelines don't allow such a title.

To view all your threads easily, just open your control panel and you can see all the threads you have subscribed to.
Jun 11 '07 #2

Motoma
Expert 2.5K+
P: 3,235
please dont mind the odd title. Its just for the sake of easyily locating that i choose the above.
Well, my problem is with left to right associativity.
please explain how it works.
Could you please elaborate on what you are looking for? It seems you have been slightly ambiguous in your question(?)...
Thanks.
Jun 11 '07 #3

P: 84
Do you mean the difference between ++a and a++ for example?

In that case, it would be the question of if you want to increment before or after an assignment. Exple:
Expand|Select|Wrap|Line Numbers
  1. a=10; 
  2. b=++a; 
  3. OR 
  4. b=a++;
  5.  
Would give always set a to 11 but in former case b is 11 (thumb rule: you assign the ++ value, ie the incremented value) while in the latter b is 10 (thumb rule: you assign then you increment).
To any moderator reading this why are there lines in the code numbered, which they shouldn't be?
Jun 11 '07 #4

Expert 10K+
P: 11,448
Some operators are left associative and some are right associative. The binary
'+' and '-' operators are both left associative, i.e.

a+b+c is evaluated as (a+b)+c
a+b-c is evaluated as (a+b)-c
a-b-c is evaluated as (a-b)-c
a-b+c is evaluated as (a-b)+c

The first expressions seems innocent, but for the last two expressions everyone
would be very surprised if they would have been evaluated in a right associative
way:

a-(b-c)
a-(b+c)

kind regards,

Jos
Jun 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.