dimanche 26 juillet 2020

Why is condition with `cout` evaluated to true?

Why if statement with condition cout << c << endl is evaluated to true.

The below code runs without showing the error. I can not understand why does it happen.

#include <iostream>

using namespace std;

int main()
{
    int c = 0;
    if (cout << c << endl) {
        c++;
    }
    cout << c <<endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire