Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are parameters of a function executed? [duplicate]

Tags:

c

Possible Duplicate:
function parameter evaluation order

Assuming that I have a function with 4 arguments. Which parameter is considered first for execution and why.

I was trying to understand the , operator's significance used for the function prototype. As is the rule is it the last variable considered first?

like image 998
Shash Avatar asked May 22 '26 17:05

Shash


1 Answers

If we have a function with the following prototype:

int function(int x, int y, int z);

And we call it like so:

function( something_a(), something_b(), something_c() );

We have no ability to presume the order of execution of something_a, something_b and something_c.

On the other hand, we can use the comma operator as follows:

int main() {
    int x;
    something_a(), something_b();
    something_c();
}

In this case, we know that something_a will be called, then something_b, and finally something_c.

In summary, the comma found in a function call, is not the comma operator.

like image 168
Bill Lynch Avatar answered May 25 '26 08:05

Bill Lynch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!