I'm trying to understand why my program won't to compile,
int myfunction(int x)
{
return x;
}
int main(){
int x = 10;
int result=0;
result=myfunction(x) * myfunction(++x);
printf("Result is = %d", result);
}
After execution i get : warnings being treated as errors In function 'int main()': operation on 'x' may be undefined. Someone has an idea ?
myfunction(x) * myfunction(++x) is undefined because the order of evaluation of the two arguments to operator * is unspecified. So either the first or second call can be executed first, meaning that theoretically x or ++x can be evaluated first, which can lead to different results. Theoretically. In practice, the standard just passes responsibility to you not to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With