Int INTSWAP; // not temporary

int INTSWAP; // not temporary

// Swaps contents of variables a and b in-place without a temporary variable.
void swap_in_place(int a, int b)
{
INTSWAP = a;
a = b;
b = INTSWAP;
}

Not sure if joke. Should I hire him?

Attached: thinking.png (960x656, 850K)

Other urls found in this thread:

tpcg.io/foV1MK
twitter.com/NSFWRedditGif

Not thread-safe. Stay away.

Attached: 1417044861882.png (620x690, 519K)

hire for what job

Don't. If it's a joke, it's shit.

a = a + b
b = a - b
a = a - b :^)

>without a temporary variable

Ask him to do it again, but this time clarify that you actually want him to only use TWO variables.

What's the use case for swapping variables when they're not being stored in some collection?

>actually asking someone to swap in-place instead of doing the responsible thing and letting the compiler do that work
He's probably taking the piss because your question is fucking stupid.

Sounds like a bold programmer who's teasing you. There's no need to believe he's overqualified, hire him.

Do it faggot, it'll be Fun

std::swap(a,b);

You know that won't swap a and b outside of the function, right?

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

He's messing with you, user. Give him something harder.

void swap(int *a, int *b)
{
*a ^= *b;
*b ^= *a;
*a ^= *b;
}

r8 & h8

not obfuscated enough or original enough, fucking generic and gay

Hire them. They're shit and will go great with the shit company that thought this shit interview question was worth asking.

this is fucking genius.
XOR swap has problems where if one of them is 0 then both become 0 and negative numbers become a hassle, but this shit works in every case, wtf user, how did you do it?

Not him, but it's literally one of the first things you can find when googling it.
Maybe he didn't come up with it on his own, maybe he did, but it's a well-known trick.

>XOR swap has problems where if one of them is 0 then both become 0 and negative numbers become a hassle
??

Attached: 2018-05-01-001631_198x229_scrot.png (198x229, 9K)

>what is value semantics

Attached: hoon_toe_kah.png (349x318, 222K)

>Not sure if joke. Should I hire him?
>// not temporary
kek

A valid concern. Post a thread safe version please.

I don't get it. What's wrong with it other than being overly verbose?

what is std::swap

Wow, I didn't expect it to be that much faster o.o
tpcg.io/foV1MK