Related Articles

Related Articles

What is evaluation order of function parameters in C?
  • Difficulty Level : Medium
  • Last Updated : 28 May, 2017

It is compiler dependent in C. It is never safe to depend on the order of evaluation of side effects. For example, a function call like below may very well behave differently from one compiler to another:

filter_none

edit
close

play_arrow

link
brightness_4
code

void func (int, int);
    
int i = 2;
func (i++, i++);

chevron_right


There is no guarantee (in either the C or the C++ standard language definitions) that the increments will be evaluated in any particular order. Either increment might happen first. func might get the arguments `2, 3′, or it might get `3, 2′, or even `2, 2′.

Source: http://gcc.gnu.org/onlinedocs/gcc/Non_002dbugs.html

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :