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

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

王林
Release: 2023-09-14 18:41:02
forward
950 people have browsed it

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++);
}
Copy after login

Output

The value of x: 12
The value of y: 11
The value of z: 10
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template