DEV Community

Discussion on: How can you swap two variables without using a third?

Collapse
 
idanarye profile image
Idan Arye
void swap(int* a, int* b) {
    write(open("swapfile", O_WRONLY | O_SYNC), a, sizeof(*a));
    *a = *b;
    read(open("swapfile", O_RDONLY), b, sizeof(*b));
}
Collapse
 
sriharsha32 profile image
SriHarsha Sreenath

Love your thinking. Nobody ever said you can't write to file and read it back :D