Can u please explain the output of the following program?

// Associativity is not used in the below program. Output
// is compiler dependent.
#include<stdio.h>
int x = 0;
int f1()
{
x = 15;
return x;
}
int f2()
{
x = 25;
return x;
}
int main()
{
int p = f1() + f2();
printf("%d ", x);
return 0;
}

In the expression
p=f1()+f2();
Both f1() and f2() are function calls and have same precedence.

So, now Associativity comes into account.
As we know the Associativity of function call is left to right

Thus, f1() will execute first and x is set to 15.
Now, f2() will execute and x is finally set to 25.

Hence, output is 25.

Hope this would hep

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.