PDA

View Full Version : Microsoft Visual C++ or TC++ or what


sharptooth
23-01-2007, 11:40 PM
Well if this not a bug than i dont understand wat it is?

i today found that "Microsoft Visual C++" v6.0 on which i performed most of my c and c++ projects, has a bug. i cud not believe it, it was a total annoy for me.

run this problem on MSVisualC++:

int x=5,y;
y=++x + ++x;
cout<<y;

the output is 14 in MSVisualC++, strange, it shud be 13.

in tc++ however it gives the correct output as 13, also 13 on C# compiler.

Now can anyone here try to clarify why MSVisualC++ gave wrong output? ?

Manshahia
26-01-2007, 06:29 PM
Wat is the Difference btw Visual C++ & TC?

morpheusv6
28-01-2007, 02:05 AM
My TC++ 3.0 shows 14.

mediator
28-01-2007, 04:21 AM
No, the output shud be 14.

I have lost touch in C++, but AFAIK for "++x" , the increment is done before the execution of the whole line. Likewise for "x++", the increment is done after the execution of the whole line.

Try this out n observe!

#include<iostream.h>
int main()
{
int x=5,y;
cout<<"\nFor x++"<<endl;
y=x++ + x++;
cout<<"x = "<<x<<endl;
cout<<"y = "<<y<<endl;

x=5,y;
cout<<"\nFor ++x"<<endl;
y=++x + ++x;
cout<<"x = "<<x<<endl;
cout<<"y = "<<y<<endl<<endl;
return 0;
}

Pathik
28-01-2007, 05:02 AM
no way man the o/p shd b 13 only