Search code examples
cconcept

What is "symmetry" in operations in C?


K&R says:

The unary + is new with the ANSI standard. It was added for symmetry with the unary -.

What is this symmetry in regards to (i.e. it's clearly not actual, geometric symmetry) and what is the significance for? Is it important in programming?


Solution

  • It's just something that means "in the pattern of", or "as you would reasonably expect given the established pattern". In this particular case - is the counterpart to +, though there are other pairs like this throughout C.

    It means you can do +2 as well as -2 and both work. It would be odd, or asymmetric, if +2 was somehow a syntax error. In fact, in K&R C there are a lot of odd things that were later ironed out in the standardization process. This appears to have been one of them.

    You don't really need a unary + operator, you can just omit the + and the code compiles fine, but by the same logic you don't need a unary - either, you can always do 0 - 5 instead of -5, though an oversight like this would seem ridiculous.