Well I have been reading quite a lot sources but they differ in definiton:
-
&& is logical operator of logical
conjunction //I guess this is correct -
&& is operator of logical AND //I
think this is not precise from
technical point of view - && is
conditional operator performing
logical AND //I think this is right
as well
While all are correct in terms of understanding, I would say the first one is most precise. Or am I mistaken?
In C#, Java, C++, C, and probably several other languages,
&&is a programming language implementation of the boolean AND operator. It is designed to account for the following facts (that do not apply in pure propositional logic):So a boolean expression in a programming language really has four possible outcomes:
true,false, “exception”, and “infinite loop”. In some situations, one has two boolean expressions where the possible success of the second expression can be determined by looking at the first expression. For instance, with the expressionsfoo != nullandfoo.bar == 42, we can be certain that if the first expression is false, then the second expression will fail. Hence, the&&operator is designed to be “short-cirquited”: If the left operand evaluates to false, the right operand is not evaluated. In all cases where both operands would evaluate successfully to true or false, this rule produces the same result as if one actually had evaluated both operands, but it allows for increased performance (because the right operand might not need to be evaluated at all) and increased compactness without sacrificing safety (if one takes care to structure the expression such that the left operand “guards” the right one). Similarly,||will not evaluate the right operand if the left operand evaluates to true.A shorter answer is that although
&&is strongly inspired by AND, it is designed to take certain programming peculiarities into account, anda && bshould perhaps rather be phrased as “an expression that returns false ifais false, and the value ofbifais true”.