int p(int *ptrP){
*ptrP=20;
return *ptrP;
}
int q(int *ptrQ){
*ptrQ=30;
return *ptrQ;
}
int main(){
int answer=0,a=10;
answer=p(&a)+q(&a); // line Alpha,for discussions sake
printf(" answer=%d a=%d ",answer,a );
}
Output:answer=50 a=30;
Swaping the Function calls in line Alpha answer=q(&a)+p(&a)
result in answer=50 a=20
, this can be justified by saying that fucntion call precedence is left to right, but when we change line alpha to answer=p(&a)+a+q(&a);
the output is answer=70 a=30
.
Where does function calling fit-in the precedence table? Are foo()+10
and 10+foo
equivalent statements?
For a more detailed explanation see the source of the quotation: https://en.cppreference.com/w/cpp/language/eval_order
So, in your case
the first function to execute may be
p
orq
.Here this rule also applies:
which means that the calls to
p
andq
, even when inlined, cannot be optimized in a way that permits their interleaving.