Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Let x and y be int variables, then the following statement: x+= y; y = x-y; y = x-y; x-= y; The function of is
Let x and y be int variables, then the following statement: x+= y; y = x-y; y = x-y; x-= y; The function of is
Answer.

The original sentence should be x+=y, y = x-y; x-= y; That makes sense. In this case,

Execute x=x+y for x+= y.

Because of x at this time, executing y=x-y leads to y = X.

Because x, y at this time, x-=y is finally executed and x=y is obtained.

For example:

X+=y is equivalent to x=x+y, and the sum of x and y is given to X.

Y=x-y=(x+y)-y=x, and assign the original value of x to y.

X-=y is equivalent to x=x-y=x+y-x=y, and the initial value of y is assigned to X.

The function of the statement is to exchange the values of x and y.

Extended data:

int a,b,c; (A, B and C are integer variables)

Long x, y; (x, y are long integer variables)

Unsigned p, q; (p, q are unsigned integer variables)

The format for defining integer variables is as follows:

Integer type 1 variable names or multiple variable names separated by commas.

Similarly, unsigned int and unsigned long variables can be defined.

Defining a variable means allocating a corresponding size of storage space for the variable in memory, and at the same time determining the storage mode and possible operations of the variable value.

Baidu Encyclopedia-Variable