473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

increment and decrement operators

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
3 1552
weaknessforcats
9,208 Expert Mod 8TB
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
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
9,208 Expert Mod 8TB
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

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

Similar topics

1
by: Hendrix | last post by:
Hi, I would like to pick four elements from a multidemensional array and use the content of those elements. I want to do this without all the subscript calls required for individual access, just...
8
by: lovecreatesbeauty | last post by:
Hello experts, Why can this difference between prefix increment/decrement and postfix increment/decrement reside in built-in operators for built-in data types? Thanks. // test.cpp // //...
5
by: Ian Pilcher | last post by:
I'm trying to figure out if an increment to a variable of an integer type, followed by a decrement, (or vice versa) is guaranteed to restore the variable to its initial value, even if the first...
8
by: Angel Tsankov | last post by:
Should pre/post increment/decrement return const or non-const? What about other functions?
5
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that...
6
by: Kevin Walzer | last post by:
This code: #include <stdio.h> int main(void) { int n1, n2; //two integers n1 = 1; n2 = 1;
8
by: cpptutor2000 | last post by:
Could some C guru please help ? I have: int x = 20, y = 35; x = x++ + y++; y = ++x + ++y; printf("%d %d\n", x, y); The answers are 57, 94 I tried reasoning using the standard C semantics...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.