c++ - std::cout with multi changing variables -


assuming code

int main(){     int i=0, j=0;      cout << << " " << f1(&i,&j) << " " << j << endl;      cout << << " " << j << endl; }  int f1(int *i, int *j){     *i = 20;     *j = 30;      return 10; } 

the result is

20 10 0 20 30 

i puzzled why j 0 while correctly shows 20

edit: have read on sequence point still unsure of how explain this. should assume j evaluated first before f1 evaluated hence j 0 , 20?

here thing:

cout << << " " << f1(&i,&j) << " " << j << endl; 

if consider right left evaluation, j 0 , printed. then, f1 called , j value changed 30. order of evaluation unpredictable


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -