-1

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?

thepufferfish
  • 441
  • 4
  • 17
  • 4
    They just mean that there's a unary minus so there might as well be a unary plus. It's not all that relevant to real world programming though I suppose you can could use it for type conversion. – PiRocks Jul 09 '20 at 18:59

1 Answers1

3

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.

tadman
  • 208,517
  • 23
  • 234
  • 262