3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by Banfa
0

Because a and b were successfully incrementented? You have putten an 'conditional or' operator between the two statements. Although I am not an C expert, usually, when the first part appears to be true the second part will not performed at all.

0

Correct C#Jaap, the logical and (&&) and or (||) operators use shortcut evaluation, that is if they can determin the result after evaluating the left hand expression they do not bother evaulating the right hand expression. For && this means if the left hand expression is false the right hand expression is not evaluated and for || this means if the left hand expression is true the right hand expression is not evaluated.

It means things like you can safely test a pointer and dereference it in the same if statement

if (valid != 0 && (*valid) != 0)
{
  // Its valid
}
else
{
  // Its not valid or valid is NULL which is also probably not valid
}   
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.