Microsoft Visual C++ or TC++ or what

Status
Not open for further replies.

sharptooth

Broken In
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++:

Code:
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? ?
 

mediator

Technomancer
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;
}
 
Status
Not open for further replies.
Top Bottom