answersLogoWhite

0

void swap (int &pa, int &pb) {

*pa ^= *pb;

*pb ^= *pa;

*pa ^= *pb;

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

How would you write a program to swap the values of character variable using call by address?

void swap (int* a, int* b) { if (!a !b) return; // can't swap a pointer to null *a^=*b^=*a^=*b; }


How do you write a program in C plus plus plus plus How do you write a program in C to swap two variables without using the third oneo swap two variables without using the third one?

To swap two variables without using a third variable, use exclusive or manipulation... a ^= b; b ^= a; a ^= b;


Swap two number using pointer?

The only way to swap two values using call by value semantics is to pass pointer variables by value. A pointer is a variable that stores an address. Passing a pointer by value copies the address, the value of the pointer, not the pointer itself. By passing the addresses of the two values to be swapped, you are effectively passing those values by reference. Both C and C++ use pass by value semantics by default, however C++ also has a reference data type to support native pass by reference semantics. By contrast, Java uses pass by reference semantics by default. In C, to swap two variables using pass by value: void swap (int* p, int* q) { int t = *p; *p = *q; *q = t; } In C++, to swap two variables using pass by reference: void swap (int& p, int& q) { std::swap (p, q); } Note that C++ is more efficient because std::swap uses move semantics; there is no temporary variable required to move variables. With copy semantics, a temporary is required. However, with primitive data types, there is a way to swap values without using a temporary, using a chain of exclusive-or assignments: void swap (int* p, int* q) { *p^=*q^=*p^=*q; }


Bubble sorting in c plus plus?

bubble_sort (int N, int *A) { int i; swap = 1; while (swap) { swap = 0; for (i=0; i<N-1; ++i) { if (A[i] > A[i+1]) { swap = 1; A[i] ^= A[i+1]; A[i+1] ^= A[i]; A[i] ^= A[i+1]; } } } }


How to swap two numbers by call by reference in c plus plus?

void swap(int& a, int& b ) { a^=b^=a^=b; }


Can you win in Uno by using a Swap Hands card?

No, you cannot win in Uno by using a Swap Hands card.


How do you swap two numbers in c plus plus?

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


SWAP out Existing Apple6s to Apple 7s plus?

YES


Wap in c plus plus for swapping contents of two variables using friend function?

Although std::swap caters for all built-in types and is specialised to cater for all STL containers, C-style arrays and strings, the default implementation may not be efficient for all user-defined types. Although you can specialise std::swap to cater for user-defined types, this is not considered best practice. The correct way to implement your own swap function is to define it as a global friend function within the same namespace as the object you're swapping so that it can be found with ADL. The following shows an example implementation: class foo : public b1, public b2 { private: int m1; float m2; public: friend void swap (foo& a, foo& b) { // import swap for built-in types using std::swap; // always swap base class members first... swap (a::b1, b::b1); swap (a::b2, b::b2); // ...then swap the members swap (a.m1, b.m1); swap (a.m2, b.m2); } };


What are the conditions to swap in c plus plus without temporary?

You can swap two integers without temporary storage by bitwise exclusive-or'ing them in a specific sequence...a ^= b;b ^= a;a ^= b;


Write a program in c plus plus to swap two no without using temp variable?

void swap(int &a,int &b) { a=a+b; b=a-b; a=a-b; } int main(void) { int a,b; cout<<"Enter the value for a and b"; cin>>a>>b; cout<<"Before swapping"<<endl; cout<<"A= "<<a<<"B= "<<b; cout<<After swapping"<<endl; swap(a,b); cout<<"A= "<<a<<"B= "<<b; return 0; }


Is there anybody willing to swap accounts in runescape they must be 70 plus?

No.