By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,222 Members | 1,728 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,222 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 ?
Sep 7 '18 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Sep 7 '18 #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.
Sep 11 '18 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Sep 11 '18 #4

Post your reply

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