Why is there a / postfix ++ prefix but no / postfix + = prefix?

This may seem like a silly question, but why do many languages ​​have a prefix and postfix version of the operator ++and --, but there are no similar versions of the prefix / postfix of other operators, such as +=or -=? For example, it seems that if I can write this code:

myArray[x++] = 137; // Write 137 to array index at x, then increment x

I should write something like

myArray[5 =+ x] = 137; // Write 137 to array index at x, then add five to x

Of course, such an operator does not exist. Is there a reason for this? This seems like weird asymmetry in C / C ++ / Java.

+3
source share
7 answers

I would suggest that there are several reasons, I think that among the more balanced ones there may be:

  • , , (, ).
  • pre/post increment ( , ), (: , , (. ).

, pre/post/increment/decment , , , . :

http://cm.bell-labs.com/cm/cs/who/dmr/chist.html

, ++ -, ; , . B, . , , DEC PDP-11, C Unix . , PDP-11, . PDP-7, , , , . , ; , , , . , , , , , ++ x , x = x + 1.

+6

y :

#define POSTADD(x,y) (((x)+=(y))-(y))
+4

. ++i/i++, (pre/post) . , while (buf[i++]) {...}. , += , 5 .

, , +=.

+2

, . , ++/- , .

+1

- ++ inc (rement) dec (rement) ( ) CPU, , .

+1

Java ++ pre-and post-increment decment, C . C , C , , PDP-11, PDP-11 INC DEC.

, , , , ; C, , . , ++i i++ , 1972 .

, C 40 .

+1

, :

x += 5;

... :

x = x + 5;

:

x + 5 = x;

, 5 =+ x, +. , htiek!

0

Source: https://habr.com/ru/post/1784310/


All Articles