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 378 views
1 answer 239 views
2 answers 331 views
1 answer 263 views
1 answer 253 views
2 answers 471 views
2 answers 298 views
...