Consider the following code. expected output should be
0 1
1 2
2 3
and so on.
#include<iostream>
using namespace std;
int f=0;
int B()
{
return f;
}
int A()
{
return f++;
}
int main()
{
cout<<A()<<" "<<B()<<endl;
cout<<A()<<" "<<B()<<endl;
cout<<A()<<" "<<B()<<endl;
cout<<A()<<" "<<B()<<endl;
return 0;
}
but the actual output is
0 0
1 1
2 2
and so on.. why?
and if i change code like this-
int main()
{
int f=0;
cout<<f++<<" "<<f<<endl;
cout<<f++<<" "<<f<<endl;
cout<<f++<<" "<<f<<endl;
cout<<f++<<" "<<f<<endl;
return 0;
}
then i get correct expected output
why?