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

Time:02-28

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

CodePudding user response:

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

CodePudding user response:

  Try using if statement
  if(booleanvaraible==true)
    functionToExecute();
  • Related