vendredi 18 janvier 2019

Post increment and assignment operator

When attempting a competitive programming question small issue was there for me. code:

#include<iostream>


int main(){
    int x = 5;

    x = x++;

    std::cout << x;

    return 0;
}

When i tried on gcc 6.3 in cmd in my system the output was:

5

When my mate tries to run on turbo c on his system output was:

6

What is this unexpected behavior and why turbo c on his system runs that code.

Is it a gcc version difference?

Aucun commentaire:

Enregistrer un commentaire