answersLogoWhite

0

#include <iostream>

int main()

{

// Declare and initialise an array with two elements.

int A[2]={1,2};

// Output the array values:

std::cout<<"Before swap:\t"<<"A[0]="<<A[0]<<", A[1]="<<A[1]<<std::endl;

// Swap the array values.

A[0]^=A[1]^=A[0]^=A[1];

// Output the array values:

std::cout<<"After swap:\t"<<"A[0]="<<A[0]<<", A[1]="<<A[1]<<std::endl;

return(0);

}

Output:

Before swap: A[0]=1, A[1]=2

After swap: A[0]=2, A[1]=1

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

Why are matrices used for representation while programming?

Let me correct you: two-dimensional arrays are used in programming to represent matrices. (Matrices are objects of mathematics, arrays are objects of programming.)


How do you swap two arrays in c plus plus using string?

You can't. While a string is a character array, an array is not necessarily a string. Treating arrays as if they were strings simply to swap them is madness. The correct way to physically swap arrays A and B is to copy A to a new array, C, then copy B to A, then C to B. If the arrays are the same size this is not a problem. If they are different sizes, you can only swap them if they are dynamic (not static). This means you must reallocate them. To speed up the process, copy the smallest array to C, first. A much better approach would be to point at the two arrays and swap the pointers instead.


How do you programme two keys simultaneusly on a Mazda 6?

If you know the steps to follow to programme your remote, all you have to do is at the time of programming 1st remote (by pressing any button) you also press any button on 2nd remote during the programming stage. Answers how to programme your remote can be found on this site.


Given two arrays A and B Array?

distinguish extra element in two arrays


How do you find the difference between two arrays in Java?

for arrays you can list the different arrays and what attributes that you give to them.


Name two smaller arrays you can use to find the product of 8x6?

name two smaller arrays you can use to find the product


What is the median of two sorted arrays?

The median of two sorted arrays is the middle value when all the numbers are combined and arranged in ascending order.


How do you get difference between two or more arrays in PHP?

The inherit function `array_dif($arrayOne, $arrayTwo, $arrayThree, ...)` is likely what you're looking for. It compares two or more arrays, and returns an array of values that are unique among the arrays.


How do you get the mean median and mode in c programming?

By writing in C code the mathematical methods for finding the mean, median and mode of your data taking into account how your data is stored (eg an array; two separate arrays one with data and the other with frequencies; a two dimensional array containing both data and frequencies; an array of structures containing the data instead of arrays; a linked list of structures; etc).


What is the Java implementation for finding the median of two sorted arrays efficiently?

One efficient Java implementation for finding the median of two sorted arrays is to merge the arrays into one sorted array and then calculate the median based on the length of the combined array.


What is the median of two arrays when combined into a single array?

To find the median of two arrays when combined into a single array, first merge the arrays and then calculate the median by finding the middle value if the total number of elements is odd, or by averaging the two middle values if the total number of elements is even.


What is the median of two sorted arrays of the same size?

The median of two sorted arrays of the same size is the middle value when all the numbers are combined and arranged in ascending order.