Originally posted by david hu:
I found that all && operator can be replaced by & operator in any program, same as || and |. So what's the point to have && and ||?
example....
if ( some_method1() || some_method2() ) {
...
...
}
So if some_method1() return true then some_method2() will be short-circuited which means it won't get to run. But what if some_method2() sets somekind of flags on some static var that u going to
test later?(not a good idea but it happens)
Then you have to use | so there wouldn't be short-circuit going on and both methods get to run. Same with &&.
On the other hand, what if you don't really need some_method2() to run if some_method1() return true?? Why do more work if you dont need to. At least the program run a bit faster and its the smart to handle it.
A lot of compiler tries to compile your code that way.
happy new year.
[This message has been edited by FEI NG (edited January 03, 2002).]