1

Topic: Swap

The task simple, I write it here, that not  in other subject: http://rsdn.org/forum/job/6878320.1 the Author: Titus Date: 19.08 11:40 There I I did not ask to solve this task, and asked absolutely about other, but for some reason there write the candidate solutions of this task, and do not write that is required on a subject. Anybody there while and did not offer the simple correct decision. Its canonical form: two whole variables an and b Are given. To make a program fragment after which execution of value of variables would exchange in places. We enter a variable c. c=a; a=b; b=c; solve the previous task, without using an additional variable.

2

Re: Swap

Hello, Titus, you wrote: T> solve the previous task, without using an additional variable. Well it is old... a = a + b b = a - b//now b = an a = a - b//now a = b

3

Re: Swap

T>> solve the previous task, without using an additional variable. DOO> well it is old... DOO> a = a + b DOO> b = a - b//now b = a DOO> a = a - b//now a = b With overflow there can be problems, and can and not to be. Depends on language/compiler/position of stars in the sky. A C/C ++: a ^ = b ^ = a ^ = b;

4

Re: Swap

Hello, Muxa, you wrote: M> Depends on language/compiler/position of stars in the sky. M> a C/C ++: a ^ = b ^ = a ^ = b; Here it precisely depends from position of stars. There and then Undefined Behaviour in the pure state: the variable without following points (well or a similar condition for other versions of languages of a C/C ++) is twice modified.

5

Re: Swap

W> Here it precisely depends from position of stars. There and then Undefined Behaviour in the pure state: the variable without following points (well or a similar condition for other versions of languages of a C/C ++) is twice modified. Under the first answer I thought a topic .

6

Re: Swap

Hello, watchmaker, you wrote: M>> a C/C ++: a ^ = b ^ = a ^ = b; W> Here it precisely depends from position of stars. There and then Undefined Behaviour in the pure state: the variable without following points is twice modified Listen, and I do not see the reasons, on which the compiler could not understand where to deliver following points: operations go from right to left, sequence accurate. Anyway over compilers gcc and MS VS stars shine correctly