= + in C ++?

I have a question about a program that includes the following if statement:

if (x =+ 4){
    x += 5;
}

I have never seen anything like this before, of course, is this not a typo? Does = + actually do something?

+4
source share
4 answers
x =+ 4

means

x= (+4)

or simply

x=4

although such a construction is syntactically correct and can be compiled, it does not make much sense and most likely typos where it was intended x==4, especially since it is used as a condition forif

+20
source

In the early days of C, it =+was the same as it was +=, but so long ago it left and never made its way into C ++.


=+a understood as = (+a)

+ int, , no-op.

= .


=+ = :

= , { Foo, int} {Foo, char}, Foo Foo a char c,

foo = c // calls the overload taking a `char`

foo =+ c // calls the overload taking an `int`

.

+1

, .

: x 4, , if 5.

:

x = 9;

, , if x == 4, x += 4, x != 4 .

0

, , , : = + = - + = - = op:

: = + C? https://www.cs.auckland.ac.nz/references/unix/digital/AQTLTBTE/DOCU_064.HTM ( -!)

, ,

https://en.wikipedia.org/wiki/C_(programming_language)#K.26R_C

tells us that they were changed: "The auxiliary form assignment operators = op (for example, = -) were changed to the form op = (i.e. - =) to remove the semantic ambiguity created by constructs such as I = -10, which was interpreted as i = -10 (decreasing i by 10) instead of the expected i = -10 (let me be -10). "

So this is not related to the explicit expression of the argument + ve or -ve. You can simply replace modern forms, for example, use + = instead of = +.

0
source

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


All Articles