Hey faggots how wuold you switch the value of 2 variables with only one operation?

hey faggots how wuold you switch the value of 2 variables with only one operation?
i have the answer, just curious of how you reflect on problems

Other urls found in this thread:

en.wikipedia.org/wiki/Assignment_(computer_science)#Parallel_assignment
twitter.com/NSFWRedditVideo

Install gentoo

install ubuntu

Do your own homework, fag.

a=b=a;

what a poorfag, ok i hope after this you will stop being butthole and starts talk serious.
when you have to swith to variables you have to declare a dummy variable right? wrong.
i tested this and it works and the program gains performances:
x=-x+(y=x)
your move now...

>swith to variables
switch the value of two variables

>y == x
>x == 0
Fucking idiot.

lol what are you talkin about you learned yesterday to code

Doesn't mean shit bcuz the uC will still use 2 instructions to change its registers values

can you please try it before judging... it works.... i wanted only to spread knowledge

x^=y^=x^=y;

a = 42
b = 69
a = a^b
b = a^b
a = a^b

$ cat test.c
#include

int main()
{
int x = 1, y = 2;

printf("%d %d\n", x, y);
x = -x + (y = x);
printf("%d %d\n", x, y);
}
$ gcc test.c
$ ./a.out
1 2
0 1

it was x=y of course at the beginnig

x=y-x+(y=x)

the most arrogant are always the most ignorant.
that kind of code is incorrect because it can over/underflow.
your code is also identical to a naive version that use temporary storage and three instructions.
you also probably have never heard of the XCHG instruction.
most languages will also first evaluate y=x and return x as the result, so that you get x = -x + x, which means that x = 0 no matter what value x and y have.

>i tested this
haha no you have not

that doesn't require additional storage but is still three instructions.

still three instructions.

x=c + (y=x)
where c is c(x,y) or c is a constant, it doesn't really matter

a, b = b, a
en.wikipedia.org/wiki/Assignment_(computer_science)#Parallel_assignment

Unless the ISA your using has an instruction for it, you can't.

oh fuck I thought he wanted with no extra variables, welp.

i misstyped it was x=y-x(y=x)

That's undefined behaviour.
You have multiple uses of the same value (with side effects) that are sequenced relative to each other.

y=x returns 1 as the result in the only good programming language, gtfo pajeet

*you're

swap(&a, &b);

again, that is incorrect you dumb friend. What happens if y is the maximum positive integer and x is the minimum negative integer?

>sequenced
unsequenced, I mean.
It's the same shit as i = ++i;

at the end of the equation x as the y value and y has the x value

The program is undefined behaviour, therefore invalid.
Any and all output is meaningless.

Either some C nested assignment magic, or many languages have memswap operation.

xchg rax, rbx

i feel like you said things looking into a mirror.
pic related ahaha