jeudi 30 septembre 2021

How statement "if(a=b){} " compiled [duplicate]

int main() {
    int a = 10; 
    int b = 5;
    if (a =b) cout << "hello";
}

I accidentally compiled the following code, but no error appeared, and hello was printed. I wonder why c++ considers the wrong comparison operation a=b to be true.

Aucun commentaire:

Enregistrer un commentaire