简体   繁体   中英

What's wrong with Macro definition in the C code?

#define TRUE 1
#define FALSE 0

void function(int var)
{
    if(var == TRUE) {
        dosomething();
    }
}

During an interview, I was showed the code. However, I think it's right. And I also try this on my computer.

Nothing is wrong with the macro definition. However, the if condition needs an explanation.

Note the difference between:

if (var == TRUE) 

1 makes the condition true and every other value makes it false.

and

if (var) 

Every value except 0 makes the condition true. Only 0 makes it false.

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