使用 AND 运算符 (&&) 在布尔值为真时调用函数

Call a function when a Boolean is true using the AND operator (&&)

在 JavaScript 中,如果某个布尔变量为真,您可以调用一个函数:

booleanVariable && functionToExecute();

是否可以在 C 中做同样的事情?

谢谢

是的,您可以:

#include <stdio.h>

int functionToExecute()
{
    printf("ran function");
    return 1;
}

int main() 
{
    int booleanVariable = 1;
    booleanVariable && functionToExecute();
    return 0;
}

https://www.mycompiler.io/view/HIbRP3W1uil