-4

See the following code:

#include<bits/stdc++.h>
using namespace std;
int read(){
    int a;
    scanf("%d", &a);
    return a;
}
void print(int a, int b){
    printf("%d %d", a, b);
}
int main(){
    print(read(), read());
}

The result of the output transitions the order of the numbers, it isn't that C++ call function operation ',' behind?

holy Ye
  • 5
  • 5

1 Answers1

0

In general, in C++, the order of evaluation of subexpressions is unspecified. Check out the link for more discussion, and some exceptional cases.

The C++ standard says:

Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced.[...]

The compiler may decide which argument of print (in your example) to evaluate first, based on efficiency or some other considerations. You should never rely on the order.

Eli Bendersky
  • 231,995
  • 78
  • 333
  • 394