answersLogoWhite

0

Swapping two values in a single statement is made possible through a series of three XOR/assign operations, alternating the operands.


Consider the following declarations:


int x = 0;

int y = 1;


The following statement will swap the values of x and y:


x ^= y ^= x ^= y; // swap



The same statement implemented as a function:


void swap(int &x, int &y){ x ^= y ^= x ^= y; }





User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

How do you find the greatest of four numbers in a single line?

If the line is horizontal, the greatest is the furthest to the right.


How many numbers are there on a single number line?

A number line stretches out for infinity. So, infinity.


Do all real numbers lie on a single line in the complex plane?

Yes. Traditionally, this line is drawn horizontally, with positive numbers to the right, and negative numbers to the left.


Is the number nine a line symmetry?

no, only single digit numbers are 8,3,1, and 0


What number is parallel to 4 on a line graph?

There should be no parallel numbers on a line graph.


Do cable companies allow multiple numbers on one line?

Cable companies allow but one number per line at a single time. The way to add numbers is by purchasing an extra line, and you may have to purchase a new number as well.


What are the mixed numbers from 3 to 7?

You should used it in a number line


Can you cross a double or single white line to make a left turn?

In the US, yes this is legal. A single or double white line signifies only that you should not change lanes.


Can you swap 302 ford engine in to a 1980 cj 5 jeep 6 cil in line?

can you swap 302 ford engine in to 1980 cj 5 jeep 6 cil. in line?


What is the relationship between a number line and multiplacation?

Do you mean a line number and multiplication? A line number is a single number and a multiplication is two numbers multiplied. One and one is two. 1X2 is 3


How you can swap the axis of a chart?

Reflect the chart in the line y = x.


How many line are on a single staff?

there should be 5 lines and 4 spaces