Here is the code which compiles :
int select_object = 0;
if( select_object ) //condition returns an int
{
printf("Hello");
}
if condition returns an int and not a boolean will the hello be printed ? When I tested this it printed hello.
Any idea why even for an int it executes the print statement.
THanks
Boolean logic
1 = True
0 = False
1 && 0 = False 0
1 && 1 = True 1
1 || 1 = True 1
1 || 0 = True 1
So the answer is for non-zero it is considered true, for 0 it is considered false. If your value (your int) returns 0 it won’t execute. If it returns a value that is not 0 it will execute.