Skip to main content
Tweeted twitter.com/StackSoftEng/status/1181766421753270272
Clarified the title
Source Link
Martin Maat
  • 18.5k
  • 3
  • 31
  • 58

Why is there nothe logical notNOT operator (!!) in C-style languages "!" and not "~~"?

For binary operators we have both bitwise and logical operators:

& bitwise AND
| bitwise OR

&& logical AND
|| logical OR

NOT (a unary operator) behaves differently though. There is just~ for bitwise and ! and it is always logical. ~ is used for binary NOTlogical.

I recognize NOT is a unary operation as opposed to AND and OR but I cannot think of a reason why the designers chose to deviate from the principle that single is bitwise and double is logical here, and went for a different character instead. I guess you could read it wrong, like a double bitwise operation that would always return the operand value. But that does not seem a real problem to me.

Is there a reason I am missing?

Why is there no logical not operator (!!) in C-style languages?

For binary operators we have both bitwise and logical operators:

& bitwise AND
| bitwise OR

&& logical AND
|| logical OR

NOT (a unary operator) behaves differently though. There is just ! and it is always logical. ~ is used for binary NOT.

I recognize NOT is a unary operation as opposed to AND and OR but I cannot think of a reason why the designers chose to deviate from the principle that single is bitwise and double is logical here, and went for a different character instead. I guess you could read it wrong, like a double bitwise operation that would always return the operand value. But that does not seem a problem to me.

Is there a reason I am missing?

Why is the logical NOT operator in C-style languages "!" and not "~~"?

For binary operators we have both bitwise and logical operators:

& bitwise AND
| bitwise OR

&& logical AND
|| logical OR

NOT (a unary operator) behaves differently though. There is ~ for bitwise and ! for logical.

I recognize NOT is a unary operation as opposed to AND and OR but I cannot think of a reason why the designers chose to deviate from the principle that single is bitwise and double is logical here, and went for a different character instead. I guess you could read it wrong, like a double bitwise operation that would always return the operand value. But that does not seem a real problem to me.

Is there a reason I am missing?

Became Hot Network Question
Source Link
Martin Maat
  • 18.5k
  • 3
  • 31
  • 58

Why is there no logical not operator (!!) in C-style languages?

For binary operators we have both bitwise and logical operators:

& bitwise AND
| bitwise OR

&& logical AND
|| logical OR

NOT (a unary operator) behaves differently though. There is just ! and it is always logical. ~ is used for binary NOT.

I recognize NOT is a unary operation as opposed to AND and OR but I cannot think of a reason why the designers chose to deviate from the principle that single is bitwise and double is logical here, and went for a different character instead. I guess you could read it wrong, like a double bitwise operation that would always return the operand value. But that does not seem a problem to me.

Is there a reason I am missing?