jeudi 27 avril 2017

Why is this code behaving so strangely? [duplicate]

This question already has an answer here:

Here is my code:

#include <bits/stdc++.h>
using namespace std;

int main () {
    int a = 5;
    cout << a++ << " " << a++ << " " << a++ << " " << ++a << endl;
    return 0;
}

Program output: 8 7 6 9

But so far as I know, the output should be 5 6 7 9

Why is the code behaving like that?

Aucun commentaire:

Enregistrer un commentaire