•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,789 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 333 | Replies: 1
![]() |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I am Anwar as a intermediate level currently programming practice in c, c++ and java . In following programs I confused in these expressions that expressions are same but result are different on these results few teachers said it is the problem of compilers.
In Turbo C 3.0
In Visual C++ 6.0
In Java 1.3
In Turbo C 3.0
main()
{int x=-250;
x = --x + --x + --x;
printf("%d",x);
}//it give -259In Visual C++ 6.0
#include<iostream>
using namespace std;
main()
{int x=-250;
x = --x + --x + --x;
cout <<x;
}//it give -257In Java 1.3
class Test
{
public static void main(String abc[])
{int x=-250;
x = --x + --x + --x;
System.out.print(x);
}//it give -256 > on these results few teachers said it is the problem of compilers.
No, it's a problem with the teachers not knowing the language rules well enough.
For C and C++, multiple side effects on the same variable has ALWAYS BEEN UNDEFINED.
What does that mean, it means the compiler is free to interpret it however it wants (or maybe even not at all). Any answer you get is just like rolling a dice.
http://c-faq.com/expr/index.html
- my answer is -256
- your answer is -257
- his hard disk has been reformatted.
As for Java, I've no idea whether the Java standard makes any claims about the evaluation order. It's certainly not comparable to C or C++.
The bottom line is that the code is broken. Don't use such constructs in your program, and don't waste time trying to figure out the mysteries of how your compiler seems to work.
No, it's a problem with the teachers not knowing the language rules well enough.
For C and C++, multiple side effects on the same variable has ALWAYS BEEN UNDEFINED.
What does that mean, it means the compiler is free to interpret it however it wants (or maybe even not at all). Any answer you get is just like rolling a dice.
http://c-faq.com/expr/index.html
- my answer is -256
- your answer is -257
- his hard disk has been reformatted.
As for Java, I've no idea whether the Java standard makes any claims about the evaluation order. It's certainly not comparable to C or C++.
The bottom line is that the code is broken. Don't use such constructs in your program, and don't waste time trying to figure out the mysteries of how your compiler seems to work.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- regular expression (PHP)
- Open In New Window Php (PHP)
- Syntax for adding two columns and sorting the results (MySQL)
- What Certifications do You Have? (Techies' Lounge)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- program (C)
- Spyware complete with EULA (Windows Users Lounge)
- write a program that simulates rooling a pair of dice. (Java)
- Data Abstraction (Computer Science and Software Design)
- For those of you who need a website database! (ASP.NET)
Other Threads in the C++ Forum
- Previous Thread: MP3 Playback in Visual C++
- Next Thread: IOS ::binary



Linear Mode