How can we predict the output of the following C++ Program

Viewed 1263

I am confused about the output of the code. It depends on what compiler i run the code. Why is it so?

#include <iostream>
using namespace std;
int f(int &n)
{   
    n--;
    return n;
}
int main()
{
      int n=10;
      n=n-f(n);
      cout<<n;
      return 0;
}

Running it on the Ubuntu terminal with g++, the output is 1 whereas running it on Turbo C++ ( the compiler we used in school) gives output as 0.

1 Answers
Related