The code is simple:
int Change(int& a)
{
a = 4;
return a;
}
int main()
{
int a = 10;
cout << Change(a) << a;
}
In C-Free : the output : 4 4
In VS2008 : the output : 4 10
Why? As I have learned, I think 4 4 is right.
The code is simple:
int Change(int& a)
{
a = 4;
return a;
}
int main()
{
int a = 10;
cout << Change(a) << a;
}
In C-Free : the output : 4 4
In VS2008 : the output : 4 10
Why? As I have learned, I think 4 4 is right.
Simply put, there is no rule that guarantees that "4 4" is right. Same goes for "4 10".
As others have mentioned in the comments you have a case of undefined behaviour here. Even if this would be defined behaviour, code like this is difficult to understand. So I recommend to do
cout << Change(a);
cout << a;
or
int b = a;
cout << Change(a);
cout << b;
whatever you really want to do.