How to create a macro that swap two values in C

1 Answer

0 votes
#include <stdio.h>

#define SWAP(x, y) (x ^= y ^= x ^= y)

int main() {

    int a = 3, b = 7;

    SWAP(a, b);

    printf("a = %d b = %d", a, b);

    return 0;
}



/*
run:

a = 7 b = 3

*/

 



answered Apr 13, 2022 by avibootz

Related questions

2 answers 244 views
1 answer 135 views
2 answers 199 views
1 answer 161 views
1 answer 146 views
2 answers 299 views
1 answer 102 views
102 views asked Apr 19, 2023 by avibootz
...