Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any downside to using the "and" operator vs the && operator? [closed]

Tags:

c++

operators

Any pros/cons to using the "and" operator vs the && operator? I personally think "and" is only going to cause confusion (ironically).

If there aren't any differences, why does it exist? It seems silly and unnecessary.

like image 825
you786 Avatar asked Feb 06 '13 23:02

you786


People also ask

What is the difference between the and and OR operators?

The difference between AND, OR is that AND evaluates both conditions must be true for the overall condition to be true. The OR evaluates one condition must be true for the overall condition to be true. In the OR result, if name is John then condition will be true.

Does the and and operator do?

Remarks. The logical AND operator ( && ) returns true if both operands are true and returns false otherwise. The operands are implicitly converted to type bool before evaluation, and the result is of type bool . Logical AND has left-to-right associativity.

What does the && and operators does not do?

The logical AND ( && ) operator (logical conjunction) for a set of boolean operands will be true if and only if all the operands are true . Otherwise it will be false .

Are the operator && and and interchangeable?

'and' and '&&' is the same operator, apart from precedence differences. They are different operators, but they operate the same, apart from precedence differences. also, using '&&' makes you look cooler.


2 Answers

It's the same operator. The difference is merely one of style. Consult your project documentation, or ask your boss, or your wife, or flip a coin.

like image 94
Kerrek SB Avatar answered Oct 20 '22 11:10

Kerrek SB


They're anachronisms - they were originally introduced to accomodate folks who didn't have "^" or "|" characters on their keyboards.

Furthermore, although "and" and "&&" are equivalent ... "and" and "&" are quite different. Using "and" instead of "&&" is simply confusing on a number of different levels, for several different reasons. Including giving the poor maintenance programmer a completely unnecessary "wtf?" experience.

I would not use them in any code. And I've certainly never seen them used in any "live" code.

IMHO...

Here's a bit more on the topic, if you're interested:

  • The written versions of the logical operators

  • http://www.cplusplus.com/reference/ciso646/

  • https://en.cppreference.com/w/cpp/language/operator_alternative

like image 44
paulsm4 Avatar answered Oct 20 '22 11:10

paulsm4