Simultaneous execution of both if and else blocks

后端 未结 13 2346
难免孤独
难免孤独 2020-12-10 17:45

In C or C++

if ( x )
    statement1;
else
    statement2;

For what value of x will both statements be executed?

I know

13条回答
  •  忘掉有多难
    2020-12-10 18:00

    In a recursive function both branches can be executed:

    void recursive(bool first)
    {
        if(first)
        {
            recursive(false);
        }
        else
        {
            //END
        }
    }
    

    Invoking it with

    recursive(true)
    

    will execute the if branch followed by the else branch

提交回复
热议问题