I am learning C so I tried the below code and am getting an output of 7,6
instead of 6,7
. Why?
#include <stdio.h>
int f1(int);
void main()
{
int b = 5;
printf("%d,%d", f1(b), f1(b));
}
int f1(int b)
{
static int n = 5;
n++;
return n;
}
Yes, it matters. The arguments must be given in the order the function expects them.
We can pass an argument to a function while calling the function by simply giving the value as an argument inside the parenthesis.
Decide if the argument is deductive or non-deductive. Determine whether the argument succeeds logically. If the argument succeeds logically, assess whether the premises are true.
evaluation order and sequence pointsOrder of evaluation of the operands of any C operator, including the order of evaluation of function arguments in a function-call expression, and the order of evaluation of the subexpressions within any expression is unspecified (except where noted below).
The order of the evaluation of the function arguments is unspecified in C. (Note there's no undefined behaviour here; the arguments are not allowed to be evaluated concurrently for example.)
Typically the evaluation of the arguments is either from right to left, or from left to right.
As a rule of thumb don't call the same function twice in a function parameter list if that function has side-effects (as it does in your case), or if you pass the same parameter twice which allows something in the calling site to be modified (e.g. passing a pointer).
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