Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which C++ logical operators do you use: and, or, not and the ilk or C style operators? why? [closed]

leisure/curiosity question as implied in the title.

I personally prefer the new operators as to make code more readable in my opinion.

Which ones do use yourself? What is your reason for choosing one over the other one?

also Emacs highlights those operators differently so I get more visual feedback when looking at the screen. I know the old operators can be highlighted as well but the ISO646 highlighted by default

like image 885
Anycorn Avatar asked Nov 09 '09 21:11

Anycorn


People also ask

What is the priority of C logical operators NOT and and OR?

C) AND (&&) > OR (||) > NOT (!) D) AND (&&) = OR (||) > NOT (!) Explanation: Logical NOT Operator in C has the highest priority.

Which operator is used for logical AND and logical or?

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 .


2 Answers

I don't think I have ever even seen C/C++ source code that actually uses the alphabetic operators. To me, it just looks strange; very un-C-ish.

like image 71
Charles Salvia Avatar answered Nov 15 '22 22:11

Charles Salvia


I prefer to use not instead of ! because it's a lot more readable:

if (not condition()) {
}

versus

if (!condition()) {
}

The ! kind of gets lost in there. Of course, this must be avoided (or #defined) when writing code intended to be portable.

However, and and or don't do much for me, so I don't use them.

like image 23
Greg Hewgill Avatar answered Nov 15 '22 20:11

Greg Hewgill