简体   繁体   中英

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

In JavaScript you can call a function if a certain Boolean variable is true:

booleanVariable && functionToExecute();

Is it possible to do the same thing in C?

Thank you

Yes, you can:

#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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM