423,335 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,335 IT Pros & Developers. It's quick & easy.

increment and decrement operators

P: 1
Is there a difference between Turbo C++ and Dev C++ because

Expand|Select|Wrap|Line Numbers
  1. int s,r=35;
  2. s=(++r)+(r++);
  3. cout<<s; 
(In Turbo C it results 72)
(In DevC++ it results 73)

How ?
2 Weeks Ago #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,163
This is garbage code:

Expand|Select|Wrap|Line Numbers
  1. s=(++r)+(r++);
C does not guarantee the order in which the statement is processed. Maybe right to left, maybe left to right, maybe some other order. Different compilers will get different answers.

Never use increment and decrement operators to a variable more than once in a statement.
2 Weeks Ago #2

P: 1
The increment and decrement operator function has no difference between Turbo C++ and Dev C++. You can check the full details from outlook support to get the full details of this.
1 Week Ago #3

weaknessforcats
Expert Mod 5K+
P: 9,163
The OP says the two compilers produce different results.

If you parse right to left you get 73. If you parse left to right you get 72.

Again, it comes down to modifying a variable more than once in the same statement. That's a no-no.
1 Week Ago #4

Post your reply

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