Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading