samedi 21 août 2021

Why is initialization `int n = ...` allowed in `if` statements? [closed]

Why would anyone do this:

#include <iostream>

int Test()
{
    return 10;
}

int main()
{
    if (int n = Test())
    {
        std::cout << "hi";
    }
}

That doesn't make any sense.

Who would use int n = Test() as an if statement?

Aucun commentaire:

Enregistrer un commentaire