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
>>61243071
Install gentoo
>>61243071
install ubuntu
>>61243071
Do your own homework, fag.
a=b=a;
>>61243080
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...
>>61243112
>swith to variables
switch the value of two variables
>>61243112
>y == x
>x == 0
Fucking idiot.
>>61243124
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
>>61243138
can you please try it before judging... it works.... i wanted only to spread knowledge
x^=y^=x^=y;
>>61243071a = 42
b = 69
a = a^b
b = a^b
a = a^b
>>61243130$ cat test.c
#include <stdio.h>
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
>>61243166
it was x=y of course at the beginnig
>>61243166
x=y-x+(y=x)
>>61243112
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
>>61243153
that doesn't require additional storage but is still three instructions.
>>61243160
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
https://en.wikipedia.org/wiki/Assignment_(computer_science)#Parallel_assignment
>>61243071
Unless the ISA your using has an instruction for it, you can't.
>>61243188
oh fuck I thought he wanted with no extra variables, welp.
>>61243188
i misstyped it was x=y-x(y=x)
>>61243185
That's undefined behaviour.
You have multiple uses of the same value (with side effects) that are sequenced relative to each other.
>>61243188
y=x returns 1 as the result in the only good programming language, gtfo pajeet
*you're
swap(&a, &b);
>>61243206
again, that is incorrect you dumb friend. What happens if y is the maximum positive integer and x is the minimum negative integer?
>>61243207
>sequenced
unsequenced, I mean.
It's the same shit asi = ++i;
>>61243207
at the end of the equation x as the y value and y has the x value
>>61243227
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.
>>61243071
xchg rax, rbx
>>61243222
>>61243222
i feel like you said things looking into a mirror.
pic related ahaha