Possible Duplicate:
Is short-circuiting boolean operators mandated in C/C++? And evaluation order?
Consider this code:
char* str=NULL;
if(str!=NULL && str[0]=='h')
printf("ok");
The first condition verified is that str is not NULL.I have tried to compile and run this code, and I don't get segmentation fault.
This means that the code breaks at the next instruction out the if, because is not needed to further verify that str[0] is equal to 'h', because it's an and.
But the question is: is this guaranteed to work with all compilers? Can't happen that the compiler generates assembly code that for some reason, first verifies that str is equal to 'h' (causing segmentation fault), and then checks that str is not NULL?