answersLogoWhite

0

In any language, you swap variables x and y using the following algorithm (assuming x, y and temp are all of the same type):

temp = x

x = y

y = temp

However, this is highly inefficient for anything other than primitive data types. For complex objects, a swap is best performed using move semantics rather than copy semantics. A move merely transfers ownership of resources rather than copying them, leaving the original owner of the resources in an unspecified but otherwise valid state.

temp = move (x)

x = move (y)

y = move (temp)

Note that objects that do not support move semantics will simply default to copy semantics.

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

What is a visual basic code?

Visual Basic code is a program or library that has been written using the Microsoft Visual Basic programming language.


Thesis topic using visual basic programming language?

visual basic thesis topics


How do you visual basic?

I think you mean how do you work visual basic. Anyways, it is a programming language developed by Microsoft using a type of basic language. I would go to a site that will teach you vb (visual basic)


How do you publish you visual basic 2008 programs on the internet?

how can i summit a solution project using visual basic 2008 through the internet


Swapping of number with using third variable?

To swap two numbers N1 and N2, using a third variable T... T = N1; N1 = N2; N2 = T;


What is class varient?

Variant is a data type in certain programming languages, particularly Visual Basic and C++ when using the Component Object Model.In Visual Basic (and Visual Basic for Applications) the Variant data type is a tagged union that can be used to represent any other data type (for example, integer, floating-point, single- and double-precision, object, etc.) except fixed-length string type and record types. In Visual Basic any variable, not declared explicitly or the type of which is not declared explicitly, is taken to be a variant.


How do you basic?

I think you mean how do you work visual basic. Anyways, it is a programming language developed by Microsoft using a type of basic language. I would go to a site that will teach you vb (visual basic)


How can you build a program using visual basic?

Download Visual Basic, Then Go Watch Tutorials on youtube or something, you'll learn over time, at least I did,


What has the author Elisabeth Boonin written?

Elisabeth Boonin has written: 'Using Excel Visual Basic for applications' -- subject(s): BASIC (Computer program language), Microsoft Visual Basic for applications


Swap logic without using third variable?

a ^= b; b ^= a; a ^= b;


Mini project in newspaper management using visual basic language?

yes


Project in college admission system using visual basic 6.0?

yes