Home  >  Article  >  Backend Development  >  What is the order of evaluation of function arguments in C?

What is the order of evaluation of function arguments in C?

王林
王林forward
2023-09-14 18:41:02898browse

What is the order of evaluation of function arguments in C?

We pass different parameters to some functions. Now we may have a question that what is the order of evaluation of function parameters. Is it from left to right or right to left?

To check the order of evaluation, we will use a simple program. Some parameters are passed here. From the output we can see how they are evaluated.

Sample code

#include<stdio.h>
void test_function(int x, int y, int z) {
   printf("The value of x: %d</p><p>", x);
   printf("The value of y: %d</p><p>", y);
   printf("The value of z: %d</p><p>", z);
}
main() {
   int a = 10;
   test_function(a++, a++, a++);
}

Output

The value of x: 12
The value of y: 11
The value of z: 10

From this output we can easily understand the evaluation sequence. First take z so it's 10, then take y so it's 11 and finally take x. So the value is 12.

The above is the detailed content of What is the order of evaluation of function arguments in C?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete