if statement - In C whether the second part of if structure is executed if first logical part failed? Is the behavior compiler depended? -


extending question what happens if first part of if-structure false?

for c programming

if((null!=b)&&(query(&b))) 

in above code part "query(&b)" executed if b=null? , behavior consistent across compilers?

no, logical operators in c short-circuit.

if attempt evaluate a && b when a false, b not evaluated.

but keep in mind you're not checking b original statement, rather you're checking a. note it's safe take address of variable that's null, can't dereference it.

i suspect should writing is:

if ((b != null) && (query (*b)) ... 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -